mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-02 04:00:36 +00:00
challenges: require challenge title, when user subscribe add new tag of challenge name. unsubscribe deletes tasks
This commit is contained in:
parent
9b41712ca6
commit
e7558139e6
3 changed files with 76 additions and 54 deletions
|
|
@ -16,7 +16,6 @@
|
|||
"guid": "*",
|
||||
"moment": "*",
|
||||
"stripe": "*",
|
||||
"lodash": "1.0.x",
|
||||
"coffee-script": "1.4.x",
|
||||
"underscore": "*",
|
||||
"mongoskin": "*",
|
||||
|
|
@ -26,7 +25,8 @@
|
|||
"resolve": "~0.2.3",
|
||||
"expect.js": "~0.2.0",
|
||||
"derby-i18n": "git://github.com/switz/derby-i18n#master",
|
||||
"relative-date": "~1.1.1"
|
||||
"relative-date": "~1.1.1",
|
||||
"lodash": "~1.2.1"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
_ = require 'underscore'
|
||||
lodash = require 'lodash'
|
||||
|
||||
module.exports.app = (appExports, model) ->
|
||||
browser = require './browser'
|
||||
|
|
@ -30,15 +31,31 @@ module.exports.app = (appExports, model) ->
|
|||
model.set '_challenge.creating', false
|
||||
|
||||
appExports.challengeSubscribe = (e) ->
|
||||
userChallenges = user.get('challenges')
|
||||
chal = e.get()
|
||||
|
||||
# Add challenge name as a tag for user
|
||||
tags = user.get('tags')
|
||||
unless tags and _.findWhere(tags,{id: chal.id})
|
||||
model.push('_user.tags', {id: chal.id, name: chal.name})
|
||||
|
||||
tags = {}; tags[chal.id] = true
|
||||
# Add all challenge's tasks to user's tasks
|
||||
userChallenges = user.get('challenges')
|
||||
user.unshift('challenges', chal.id) unless userChallenges and (userChallenges.indexOf(chal.id) != -1)
|
||||
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
|
||||
_.each chal["#{type}s"], (task) -> model.push("_#{type}List", task)
|
||||
_.each chal["#{type}s"], (task) ->
|
||||
task.tags = tags
|
||||
task.challenge = chal.id
|
||||
model.push("_#{type}List", task)
|
||||
|
||||
appExports.challengeUnsubscribe = (e) ->
|
||||
i = user.get('challenges')?.indexOf e.get('id')
|
||||
chal = e.get()
|
||||
i = user.get('challenges')?.indexOf chal.id
|
||||
user.remove("challenges.#{i}") if i? and i != -1
|
||||
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
|
||||
_.each chal["#{type}s"], (task) ->
|
||||
model.remove "_#{type}List", lodash.findIndex(model.get("_#{type}List",{id:task.id}))
|
||||
model.del "_user.tasks.#{task.id}"
|
||||
|
||||
appExports.challengeCollapse = (e, el) ->
|
||||
$(el).next().toggle()
|
||||
|
|
|
|||
|
|
@ -33,24 +33,23 @@
|
|||
|
||||
<div class="tab-pane" id="challengesViewParty">
|
||||
{#each _party.challenges as :challenge}
|
||||
<div class='pull-right'>
|
||||
{#if indexOf(_user.challenges,:challenge.id)}
|
||||
<a x-bind="click:challengeUnsubscribe" class='btn btn-large btn-danger'><i class='icon-ban-circle'></i> Unsubscribe</a>
|
||||
{else}
|
||||
<a x-bind="click:challengeSubscribe" class='btn btn-large btn-success'><i class='icon-ok'></i> Subscribe</a>
|
||||
{/}
|
||||
</div>
|
||||
<h3 x-bind="click:challengeCollapse"><i class='icon-chevron-down icon-chevron-right'></i> {:challenge.name} (by {:challenge.user})</h3>
|
||||
<div>
|
||||
<div class='pull-right'>
|
||||
<a x-bind="click:challengeUnsubscribe" class='btn btn-large btn-danger {#unless indexOf(_user.challenges,:challenge.id)}hidden{/}'><i class='icon-ban-circle'></i> Unsubscribe</a>
|
||||
<a x-bind="click:challengeSubscribe" class='btn btn-large btn-success {#if indexOf(_user.challenges,:challenge.id)}hidden{/}'><i class='icon-ok'></i> Subscribe</a>
|
||||
</div>
|
||||
<h3 x-bind="click:challengeCollapse"><i class='icon-chevron-down icon-chevron-right'></i> {:challenge.name} (by {:challenge.user})</h3>
|
||||
|
||||
|
||||
<div class="grid">
|
||||
<app:tasks:task-lists
|
||||
habits={:challenge.habits}
|
||||
dailys={:challenge.dailys}
|
||||
todos={:challenge.todos}
|
||||
rewards={:challenge.rewards} />
|
||||
<div class="grid">
|
||||
<app:tasks:task-lists
|
||||
habits={:challenge.habits}
|
||||
dailys={:challenge.dailys}
|
||||
todos={:challenge.todos}
|
||||
rewards={:challenge.rewards} />
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
<hr/>
|
||||
{/}
|
||||
</div>
|
||||
|
||||
|
|
@ -70,7 +69,6 @@
|
|||
{#unless _challenge.creating}
|
||||
<a x-bind='click:challengeCreate' class='btn btn-large btn-success'>Create New Challenge</a>
|
||||
{else}
|
||||
<input id='newChallengeName' type='text' value={_challenge.new.name} placeholder="Challenge Title" required/>
|
||||
|
||||
<div class="grid">
|
||||
<app:tasks:task-lists
|
||||
|
|
@ -81,43 +79,50 @@
|
|||
editable=true />
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<div>
|
||||
<select>
|
||||
<option selected="{equal('Party',_challenge.new.assignTo)}" >Party</option>
|
||||
<option selected="{equal('Guild',_challenge.new.assignTo)}" >Guild</option>
|
||||
<option selected="{equal('Public',_challenge.new.assignTo)}" >Public</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
{#if equal(_challenge.new.assignTo,'Party')}
|
||||
<div class='row-fluid'>
|
||||
<div class='span4 well'>
|
||||
<div><input type='radio' name='challenge-party-selection' checked={_challenge.new.partyAssignees} >All Party</input></div>
|
||||
<small>No individual privacy on the challenge, all party members can see progress even if they decline the challenge. Any new party members can subscribe to this challenge.</small>
|
||||
</div>
|
||||
<div class='span8 well'>
|
||||
<div><input type='radio' name='challenge-party-selection' checked={not(_challenge.new.partyAssignees)} >Individual Members</input></div>
|
||||
<div>
|
||||
<select multiple="multiple">
|
||||
{{#each _partyMembers as :member}}
|
||||
<option>{{username(:member.auth,:member.profile.name)}}</option>
|
||||
{{/}}
|
||||
</select>
|
||||
<form x-bind="submit:challengeSave">
|
||||
|
||||
<input id='newChallengeName' type='text' value={_challenge.new.name} placeholder="Challenge Title" required />
|
||||
|
||||
<fieldset>
|
||||
<div>
|
||||
<select>
|
||||
<option selected="{equal('Party',_challenge.new.assignTo)}" >Party</option>
|
||||
<option selected="{equal('Guild',_challenge.new.assignTo)}" >Guild</option>
|
||||
<option selected="{equal('Public',_challenge.new.assignTo)}" >Public</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
{#if equal(_challenge.new.assignTo,'Party')}
|
||||
<div class='row-fluid'>
|
||||
<div class='span4 well'>
|
||||
<div><input type='radio' name='challenge-party-selection' checked={_challenge.new.partyAssignees} >All Party</input></div>
|
||||
<small>No individual privacy on the challenge, all party members can see progress even if they decline the challenge. Any new party members can subscribe to this challenge.</small>
|
||||
</div>
|
||||
<div class='span8 well'>
|
||||
<div><input type='radio' name='challenge-party-selection' checked={not(_challenge.new.partyAssignees)} >Individual Members</input></div>
|
||||
<div>
|
||||
<select multiple="multiple">
|
||||
{{#each _partyMembers as :member}}
|
||||
<option>{{username(:member.auth,:member.profile.name)}}</option>
|
||||
{{/}}
|
||||
</select>
|
||||
</div>
|
||||
<div><small>Only the invited party members can subscribe to this challenge. New party joins won't see this challenge.</small></div>
|
||||
</div>
|
||||
<div><small>Only the invited party members can subscribe to this challenge. New party joins won't see this challenge.</small></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/}
|
||||
{#if equal(_challenge.new.assignTo,'Guild')}
|
||||
Which Guild?
|
||||
{/}
|
||||
</div>
|
||||
</fieldset>
|
||||
{/}
|
||||
{#if equal(_challenge.new.assignTo,'Guild')}
|
||||
Which Guild?
|
||||
{/}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<input type='submit' class='btn btn-large btn-success' value='Save' />
|
||||
<input type='button' x-bind='click:challengeDiscard' class='btn btn-large btn-danger' value=Discard />
|
||||
</form>
|
||||
|
||||
|
||||
<input type='submit' x-bind="click:challengeSave" class='btn btn-large btn-success' value='Save' />
|
||||
<input type='button' x-bind='click:challengeDiscard' class='btn btn-large btn-danger' value=Discard />
|
||||
{/}
|
||||
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue