Challenge fixes (#9528)

* Added challenge member search to progress dropdown

* Added leave challenge modal

* Allowed editing for challenge leader only

* Pevented users from editing challenge task info

* Set default progress default to daily

* Removed reward filters from user challenge progress
This commit is contained in:
Keith Holliday
2017-11-17 17:13:07 -06:00
committed by GitHub
parent c06d5107ac
commit 9c2f5213cb
8 changed files with 147 additions and 56 deletions

View File

@@ -1,6 +1,7 @@
<template lang="pug"> <template lang="pug">
.row .row
challenge-modal(:cloning='cloning' v-on:updatedChallenge='updatedChallenge') challenge-modal(:cloning='cloning' v-on:updatedChallenge='updatedChallenge')
leave-challenge-modal(:challengeId='challenge._id')
close-challenge-modal(:members='members', :challengeId='challenge._id') close-challenge-modal(:members='members', :challengeId='challenge._id')
challenge-member-progress-modal(:memberId='progressMemberId', :challengeId='challenge._id') challenge-member-progress-modal(:memberId='progressMemberId', :challengeId='challenge._id')
@@ -33,7 +34,8 @@
span.view-progress span.view-progress
strong {{ $t('viewProgressOf') }} strong {{ $t('viewProgressOf') }}
b-dropdown.create-dropdown(text="Select a Participant") b-dropdown.create-dropdown(text="Select a Participant")
b-dropdown-item(v-for="member in members", :key="member._id", @click="openMemberProgressModal(member._id)") input.form-control(type='text', v-model='searchTerm')
b-dropdown-item(v-for="member in memberResults", :key="member._id", @click="openMemberProgressModal(member._id)")
| {{ member.profile.name }} | {{ member.profile.name }}
span(v-if='isLeader || isAdmin') span(v-if='isLeader || isAdmin')
b-dropdown.create-dropdown(:text="$t('addTaskToChallenge')", :variant="'success'") b-dropdown.create-dropdown(:text="$t('addTaskToChallenge')", :variant="'success'")
@@ -189,6 +191,8 @@ import TaskModal from '../tasks/taskModal';
import markdownDirective from 'client/directives/markdown'; import markdownDirective from 'client/directives/markdown';
import challengeModal from './challengeModal'; import challengeModal from './challengeModal';
import challengeMemberProgressModal from './challengeMemberProgressModal'; import challengeMemberProgressModal from './challengeMemberProgressModal';
import challengeMemberSearchMixin from 'client/mixins/challengeMemberSearch';
import leaveChallengeModal from './leaveChallengeModal';
import taskDefaults from 'common/script/libs/taskDefaults'; import taskDefaults from 'common/script/libs/taskDefaults';
@@ -198,11 +202,13 @@ import calendarIcon from 'assets/svg/calendar.svg';
export default { export default {
props: ['challengeId'], props: ['challengeId'],
mixins: [challengeMemberSearchMixin],
directives: { directives: {
markdown: markdownDirective, markdown: markdownDirective,
}, },
components: { components: {
closeChallengeModal, closeChallengeModal,
leaveChallengeModal,
challengeModal, challengeModal,
challengeMemberProgressModal, challengeMemberProgressModal,
TaskColumn: Column, TaskColumn: Column,
@@ -231,6 +237,8 @@ export default {
workingTask: {}, workingTask: {},
taskFormPurpose: 'create', taskFormPurpose: 'create',
progressMemberId: '', progressMemberId: '',
searchTerm: '',
memberResults: [],
}; };
}, },
computed: { computed: {
@@ -365,19 +373,7 @@ export default {
await this.$store.dispatch('tasks:fetchUserTasks', {forceLoad: true}); await this.$store.dispatch('tasks:fetchUserTasks', {forceLoad: true});
}, },
async leaveChallenge () { async leaveChallenge () {
let keepChallenge = confirm('Do you want to keep challenge tasks?'); this.$root.$emit('bv::show::modal', 'leave-challenge-modal');
let keep = 'keep-all';
if (!keepChallenge) keep = 'remove-all';
let index = findIndex(this.user.challenges, (challengeId) => {
return challengeId === this.searchId;
});
this.user.challenges.splice(index, 1);
await this.$store.dispatch('challenges:leaveChallenge', {
challengeId: this.searchId,
keep,
});
await this.$store.dispatch('tasks:fetchUserTasks', {forceLoad: true});
}, },
closeChallenge () { closeChallenge () {
this.$root.$emit('bv::show::modal', 'close-challenge-modal'); this.$root.$emit('bv::show::modal', 'close-challenge-modal');

View File

@@ -74,10 +74,11 @@ div
</style> </style>
<script> <script>
import debounce from 'lodash/debounce'; import challengeMemberSearchMixin from 'client/mixins/challengeMemberSearch';
export default { export default {
props: ['challengeId', 'members'], props: ['challengeId', 'members'],
mixins: [challengeMemberSearchMixin],
data () { data () {
return { return {
winner: {}, winner: {},
@@ -85,14 +86,6 @@ export default {
memberResults: [], memberResults: [],
}; };
}, },
watch: {
searchTerm: debounce(function searchTerm (newSearch) {
this.searchChallengeMember(newSearch);
}, 500),
members () {
this.memberResults = this.members;
},
},
computed: { computed: {
winnerText () { winnerText () {
if (!this.winner.profile) return this.$t('selectMember'); if (!this.winner.profile) return this.$t('selectMember');
@@ -100,12 +93,6 @@ export default {
}, },
}, },
methods: { methods: {
async searchChallengeMember (search) {
this.memberResults = await this.$store.dispatch('members:getChallengeMembers', {
challengeId: this.challengeId,
searchTerm: search,
});
},
selectMember (member) { selectMember (member) {
this.winner = member; this.winner = member;
}, },

View File

@@ -0,0 +1,45 @@
<template lang="pug">
b-modal#leave-challenge-modal(:title="$t('leaveChallenge')", size='sm', :hide-footer="true")
.modal-body
h2 {{ $t('confirmKeepChallengeTasks') }}
div
button.btn.btn-primary(@click='leaveChallenge("keep")') {{ $t('keepIt') }}
button.btn.btn-danger(@click='leaveChallenge("remove-all")') {{ $t('removeIt') }}
</template>
<style scoped>
.modal-body {
padding-bottom: 2em;
}
</style>
<script>
import findIndex from 'lodash/findIndex';
import { mapState } from 'client/libs/store';
import notifications from 'client/mixins/notifications';
export default {
props: ['challengeId'],
mixins: [notifications],
computed: {
...mapState({user: 'user.data'}),
},
methods: {
async leaveChallenge (keep) {
let index = findIndex(this.user.challenges, (id) => {
return id === this.challengeId;
});
this.user.challenges.splice(index, 1);
await this.$store.dispatch('challenges:leaveChallenge', {
challengeId: this.challengeId,
keep,
});
await this.$store.dispatch('tasks:fetchUserTasks', {forceLoad: true});
this.close();
},
close () {
this.$root.$emit('bv::hide::modal', 'leave-challenge-modal');
},
},
};
</script>

View File

@@ -11,7 +11,7 @@
select.form-control(v-model="workingGroup.newLeader") select.form-control(v-model="workingGroup.newLeader")
option(v-for='potentialLeader in potentialLeaders', :value="potentialLeader._id") {{ potentialLeader.name }} option(v-for='potentialLeader in potentialLeaders', :value="potentialLeader._id") {{ potentialLeader.name }}
.form-group(v-if='!this.workingGroup.id') .form-group
label label
strong(v-once) {{$t('privacySettings')}} * strong(v-once) {{$t('privacySettings')}} *
br br
@@ -35,7 +35,7 @@
// @TODO discuss the impact of this with moderators before implementing // @TODO discuss the impact of this with moderators before implementing
br br
label.custom-control.custom-checkbox(v-if='!isParty') label.custom-control.custom-checkbox(v-if='!isParty && !this.workingGroup.id')
input.custom-control-input(type="checkbox", v-model="workingGroup.privateGuild") input.custom-control-input(type="checkbox", v-model="workingGroup.privateGuild")
span.custom-control-indicator span.custom-control-indicator
span.custom-control-description(v-once) {{ $t('privateGuild') }} span.custom-control-description(v-once) {{ $t('privateGuild') }}
@@ -345,6 +345,9 @@ export default {
if (editingGroup.summary) this.workingGroup.summary = editingGroup.summary; if (editingGroup.summary) this.workingGroup.summary = editingGroup.summary;
if (editingGroup.description) this.workingGroup.description = editingGroup.description; if (editingGroup.description) this.workingGroup.description = editingGroup.description;
if (editingGroup._id) this.workingGroup.id = editingGroup._id; if (editingGroup._id) this.workingGroup.id = editingGroup._id;
this.workingGroup.onlyLeaderCreatesChallenges = editingGroup.leaderOnly.challenges;
if (editingGroup.leader._id) { if (editingGroup.leader._id) {
this.workingGroup.newLeader = editingGroup.leader._id; this.workingGroup.newLeader = editingGroup.leader._id;
this.workingGroup.currentLeaderId = editingGroup.leader._id; this.workingGroup.currentLeaderId = editingGroup.leader._id;
@@ -410,11 +413,9 @@ export default {
this.workingGroup.privacy = 'public'; this.workingGroup.privacy = 'public';
} }
if (!this.workingGroup.onlyLeaderCreatesChallenges) {
this.workingGroup.leaderOnly = { this.workingGroup.leaderOnly = {
challenges: true, challenges: this.workingGroup.onlyLeaderCreatesChallenges,
}; };
}
let categoryKeys = this.workingGroup.categories; let categoryKeys = this.workingGroup.categories;
let serverCategories = []; let serverCategories = [];

View File

@@ -64,7 +64,6 @@
@click.prevent.stop="togglePinned(ctx.item)" @click.prevent.stop="togglePinned(ctx.item)"
) )
span.svg-icon.inline.icon-12.color(v-html="icons.pin") span.svg-icon.inline.icon-12.color(v-html="icons.pin")
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -334,6 +333,16 @@ export default {
user: 'user.data', user: 'user.data',
userPreferences: 'user.data.preferences', userPreferences: 'user.data.preferences',
}), }),
onUserPage () {
let onUserPage = Boolean(this.taskList.length) && (!this.taskListOverride || this.taskListOverride.length === 0);
if (!onUserPage) {
this.activateFilter('daily', this.types.daily.filters[0]);
this.types.reward.filters = [];
}
return onUserPage;
},
taskList () { taskList () {
// @TODO: This should not default to user's tasks. It should require that you pass options in // @TODO: This should not default to user's tasks. It should require that you pass options in
const filter = this.activeFilters[this.type]; const filter = this.activeFilters[this.type];
@@ -399,6 +408,7 @@ export default {
if (this.user.preferences.dailyDueDefaultView) { if (this.user.preferences.dailyDueDefaultView) {
this.activateFilter('daily', this.types.daily.filters[1]); this.activateFilter('daily', this.types.daily.filters[1]);
} }
return this.user.preferences.dailyDueDefaultView; return this.user.preferences.dailyDueDefaultView;
}, },
quickAddPlaceholder () { quickAddPlaceholder () {
@@ -434,9 +444,8 @@ export default {
deep: true, deep: true,
}, },
dailyDueDefaultView () { dailyDueDefaultView () {
if (this.user.preferences.dailyDueDefaultView) { if (!this.dailyDueDefaultView) return;
this.activateFilter('daily', this.types.daily.filters[1]); this.activateFilter('daily', this.types.daily.filters[1]);
}
}, },
}, },
mounted () { mounted () {
@@ -526,6 +535,7 @@ export default {
if (type === 'todo' && filter.label === 'complete2') { if (type === 'todo' && filter.label === 'complete2') {
this.loadCompletedTodos(); this.loadCompletedTodos();
} }
this.activeFilters[type] = filter; this.activeFilters[type] = filter;
}, },
setColumnBackgroundVisibility () { setColumnBackgroundVisibility () {

View File

@@ -13,7 +13,7 @@
type="text", :class="[`${cssClass}-modal-input`]", type="text", :class="[`${cssClass}-modal-input`]",
required, v-model="task.text", required, v-model="task.text",
autofocus, spellcheck="true", autofocus, spellcheck="true",
:disabled="groupAccessRequiredAndOnPersonalPage" :disabled="groupAccessRequiredAndOnPersonalPage || challengeAccessRequired"
) )
.form-group .form-group
label(v-once) {{ $t('notes') }} label(v-once) {{ $t('notes') }}
@@ -34,12 +34,12 @@
.svg-icon.destroy-icon(v-html="icons.destroy") .svg-icon.destroy-icon(v-html="icons.destroy")
input.inline-edit-input.checklist-item.form-control(type="text", :placeholder="$t('newChecklistItem')", @keydown.enter="addChecklistItem($event)", v-model="newChecklistItem") input.inline-edit-input.checklist-item.form-control(type="text", :placeholder="$t('newChecklistItem')", @keydown.enter="addChecklistItem($event)", v-model="newChecklistItem")
.d-flex.justify-content-center(v-if="task.type === 'habit'") .d-flex.justify-content-center(v-if="task.type === 'habit'")
.option-item(:class="optionClass(task.up === true)", @click="task.up = !task.up") .option-item(:class="optionClass(task.up === true)", @click="toggleUpDirection()")
.option-item-box .option-item-box
.task-control.habit-control(:class="controlClass.up + '-control-habit'") .task-control.habit-control(:class="controlClass.up + '-control-habit'")
.svg-icon.positive(v-html="icons.positive") .svg-icon.positive(v-html="icons.positive")
.option-item-label(v-once) {{ $t('positive') }} .option-item-label(v-once) {{ $t('positive') }}
.option-item(:class="optionClass(task.down === true)", @click="task.down = !task.down") .option-item(:class="optionClass(task.down === true)", @click="toggleDownDirection()")
.option-item-box .option-item-box
.task-control.habit-control(:class="controlClass.down + '-control-habit'") .task-control.habit-control(:class="controlClass.down + '-control-habit'")
.svg-icon.negative(v-html="icons.negative") .svg-icon.negative(v-html="icons.negative")
@@ -49,19 +49,19 @@
span.float-left {{ $t('difficulty') }} span.float-left {{ $t('difficulty') }}
// @TODO .svg-icon.info-icon(v-html="icons.information") // @TODO .svg-icon.info-icon(v-html="icons.information")
.d-flex.justify-content-center .d-flex.justify-content-center
.option-item(:class="optionClass(task.priority === 0.1)", @click="task.priority = 0.1") .option-item(:class="optionClass(task.priority === 0.1)", @click="setDifficulty(0.1)")
.option-item-box .option-item-box
.svg-icon.difficulty-trivial-icon(v-html="icons.difficultyTrivial") .svg-icon.difficulty-trivial-icon(v-html="icons.difficultyTrivial")
.option-item-label(v-once) {{ $t('trivial') }} .option-item-label(v-once) {{ $t('trivial') }}
.option-item(:class="optionClass(task.priority === 1)", @click="task.priority = 1") .option-item(:class="optionClass(task.priority === 1)", @click="setDifficulty(1)")
.option-item-box .option-item-box
.svg-icon.difficulty-normal-icon(v-html="icons.difficultyNormal") .svg-icon.difficulty-normal-icon(v-html="icons.difficultyNormal")
.option-item-label(v-once) {{ $t('easy') }} .option-item-label(v-once) {{ $t('easy') }}
.option-item(:class="optionClass(task.priority === 1.5)", @click="task.priority = 1.5") .option-item(:class="optionClass(task.priority === 1.5)", @click="setDifficulty(1.5)")
.option-item-box .option-item-box
.svg-icon.difficulty-medium-icon(v-html="icons.difficultyMedium") .svg-icon.difficulty-medium-icon(v-html="icons.difficultyMedium")
.option-item-label(v-once) {{ $t('medium') }} .option-item-label(v-once) {{ $t('medium') }}
.option-item(:class="optionClass(task.priority === 2)", @click="task.priority = 2") .option-item(:class="optionClass(task.priority === 2)", @click="setDifficulty(2)")
.option-item-box .option-item-box
.svg-icon.difficulty-hard-icon(v-html="icons.difficultyHard") .svg-icon.difficulty-hard-icon(v-html="icons.difficultyHard")
.option-item-label(v-once) {{ $t('hard') }} .option-item-label(v-once) {{ $t('hard') }}
@@ -72,28 +72,33 @@
:clearButton='true', :clearButton='true',
clearButtonIcon='category-select', clearButtonIcon='category-select',
:clearButtonText='$t("clear")', :clearButtonText='$t("clear")',
:todayButton='true', :todayButton='!challengeAccessRequired',
todayButtonIcon='category-select', todayButtonIcon='category-select',
:todayButtonText='$t("today")', :todayButtonText='$t("today")',
:disabled-picker='challengeAccessRequired'
) )
.option(v-if="task.type === 'daily'") .option(v-if="task.type === 'daily'")
label(v-once) {{ $t('startDate') }} label(v-once) {{ $t('startDate') }}
datepicker.d-inline-block( datepicker.d-inline-block(
v-model="task.startDate", v-model="task.startDate",
:clearButton='false', :clearButton='false',
:todayButton='true', :todayButton='!challengeAccessRequired',
todayButtonIcon='category-select', todayButtonIcon='category-select',
:todayButtonText='$t("today")', :todayButtonText='$t("today")',
:disabled-picker='challengeAccessRequired'
) )
.option(v-if="task.type === 'daily'") .option(v-if="task.type === 'daily'")
.form-group .form-group
label(v-once) {{ $t('repeats') }} label(v-once) {{ $t('repeats') }}
b-dropdown(:text="$t(task.frequency)") b-dropdown(:text="$t(task.frequency)")
b-dropdown-item(v-for="frequency in ['daily', 'weekly', 'monthly', 'yearly']", :key="frequency", @click="task.frequency = frequency", :class="{active: task.frequency === frequency}") b-dropdown-item(v-for="frequency in ['daily', 'weekly', 'monthly', 'yearly']",
:key="frequency", @click="task.frequency = frequency",
:disabled='challengeAccessRequired',
:class="{active: task.frequency === frequency}")
| {{ $t(frequency) }} | {{ $t(frequency) }}
.form-group .form-group
label(v-once) {{ $t('repeatEvery') }} label(v-once) {{ $t('repeatEvery') }}
input(type="number", v-model="task.everyX", min="0", required) input(type="number", v-model="task.everyX", min="0", required, :disabled='challengeAccessRequired')
| {{ repeatSuffix }} | {{ repeatSuffix }}
br br
template(v-if="task.frequency === 'weekly'") template(v-if="task.frequency === 'weekly'")
@@ -102,7 +107,7 @@
:key="dayNumber", :key="dayNumber",
) )
label.custom-control.custom-checkbox label.custom-control.custom-checkbox
input.custom-control-input(type="checkbox", v-model="task.repeat[day]") input.custom-control-input(type="checkbox", v-model="task.repeat[day]", :disabled='challengeAccessRequired')
span.custom-control-indicator span.custom-control-indicator
span.custom-control-description(v-once) {{ weekdaysMin(dayNumber) }} span.custom-control-description(v-once) {{ weekdaysMin(dayNumber) }}
template(v-if="task.frequency === 'monthly'") template(v-if="task.frequency === 'monthly'")
@@ -118,7 +123,7 @@
.tags-select.option(v-if="isUserTask") .tags-select.option(v-if="isUserTask")
.tags-inline .tags-inline
label(v-once) {{ $t('tags') }} label(v-once) {{ $t('tags') }}
.category-wrap(@click="showTagsSelect = !showTagsSelect", v-bind:class="{ active: showTagsSelect }") .category-wrap(@click="toggleTagSelect()", v-bind:class="{ active: showTagsSelect }")
span.category-select(v-if='task.tags && task.tags.length === 0') span.category-select(v-if='task.tags && task.tags.length === 0')
.tags-none {{$t('none')}} .tags-none {{$t('none')}}
.dropdown-toggle .dropdown-toggle
@@ -137,7 +142,7 @@
.option(v-if="task.type === 'daily' && isUserTask && purpose === 'edit'") .option(v-if="task.type === 'daily' && isUserTask && purpose === 'edit'")
.form-group .form-group
label(v-once) {{ $t('restoreStreak') }} label(v-once) {{ $t('restoreStreak') }}
input(type="number", v-model="task.streak", min="0", required) input(type="number", v-model="task.streak", min="0", required, :disabled='challengeAccessRequired')
.option.group-options(v-if='groupId') .option.group-options(v-if='groupId')
label(v-once) Assigned To label(v-once) Assigned To
@@ -598,12 +603,21 @@ export default {
dayMapping: 'constants.DAY_MAPPING', dayMapping: 'constants.DAY_MAPPING',
}), }),
groupAccessRequiredAndOnPersonalPage () { groupAccessRequiredAndOnPersonalPage () {
if (!this.groupId && this.task.group.id) return true; if (!this.groupId && this.task.group && this.task.group.id) return true;
return false; return false;
}, },
checklistEnabled () { checklistEnabled () {
return ['daily', 'todo'].indexOf(this.task.type) > -1 && !this.isOriginalChallengeTask; return ['daily', 'todo'].indexOf(this.task.type) > -1 && !this.isOriginalChallengeTask;
}, },
isChallengeTask () {
return Boolean(this.task.challenge && this.task.challenge.id);
},
onUserPage () {
return !this.challengeId && !this.groupId;
},
challengeAccessRequired () {
return this.onUserPage && this.isChallengeTask;
},
isOriginalChallengeTask () { isOriginalChallengeTask () {
let isUserChallenge = Boolean(this.task.userId); let isUserChallenge = Boolean(this.task.userId);
return !isUserChallenge && (this.challengeId || this.task.challenge && this.task.challenge.id); return !isUserChallenge && (this.challengeId || this.task.challenge && this.task.challenge.id);
@@ -682,6 +696,22 @@ export default {
closeTagsPopup () { closeTagsPopup () {
this.showTagsSelect = false; this.showTagsSelect = false;
}, },
setDifficulty (level) {
if (this.challengeAccessRequired) return;
this.task.priority = level;
},
toggleUpDirection () {
if (this.challengeAccessRequired) return;
this.task.up = !this.task.up;
},
toggleDownDirection () {
if (this.challengeAccessRequired) return;
this.task.down = !this.task.down;
},
toggleTagSelect () {
if (this.challengeAccessRequired) return;
this.showTagsSelect = !this.showTagsSelect;
},
sortedChecklist (data) { sortedChecklist (data) {
let sorting = clone(this.task.checklist); let sorting = clone(this.task.checklist);
let movingItem = sorting[data.oldIndex]; let movingItem = sorting[data.oldIndex];

View File

@@ -0,0 +1,21 @@
// @TODO: How do we require data or make this functional
import debounce from 'lodash/debounce';
export default {
watch: {
searchTerm: debounce(function searchTerm (newSearch) {
this.challengeMemberSearchMixin_searchChallengeMember(newSearch);
}, 500),
members () {
this.memberResults = this.members;
},
},
methods: {
async challengeMemberSearchMixin_searchChallengeMember (search) { // eslint-disable-line
this.memberResults = await this.$store.dispatch('members:getChallengeMembers', {
challengeId: this.challengeId,
searchTerm: search,
});
},
},
};

View File

@@ -129,5 +129,6 @@
"locationRequired": "Location of challenge is required ('Add to')", "locationRequired": "Location of challenge is required ('Add to')",
"categoiresRequired": "One or more categories must be selected", "categoiresRequired": "One or more categories must be selected",
"viewProgressOf": "View Progress Of", "viewProgressOf": "View Progress Of",
"selectMember": "Select Member" "selectMember": "Select Member",
"confirmKeepChallengeTasks": "Do you want to keep challenge tasks?"
} }