New client challenge tasks (#8915)

* Added get and create challenge tasks

* Added challenge task edit
This commit is contained in:
Keith Holliday
2017-08-02 10:57:57 -06:00
committed by GitHub
parent e3b10cdc2a
commit cf0ce90968
8 changed files with 467 additions and 371 deletions

View File

@@ -93,6 +93,7 @@ export default {
data () { data () {
let tweet = this.$t('levelUpShare'); let tweet = this.$t('levelUpShare');
return { return {
statsAllocationBoxIsOpen: true,
maxHealth, maxHealth,
tweet, tweet,
socialLevelLink: `${BASE_URL}/social/level-up`, socialLevelLink: `${BASE_URL}/social/level-up`,

View File

@@ -26,7 +26,12 @@
| {{challenge.prize}} | {{challenge.prize}}
.details(v-once) {{$t('prize')}} .details(v-once) {{$t('prize')}}
.row .row
task-column.col-6(v-for="column in columns", :type="column", :key="column") task-column.col-6(
v-for="column in columns",
:type="column",
:key="column",
:taskListOverride='tasksByType[column]',
v-on:editTask="editTask")
.col-4.sidebar.standard-page .col-4.sidebar.standard-page
.acitons .acitons
div(v-if='!isMember && !isLeader') div(v-if='!isMember && !isLeader')
@@ -34,7 +39,19 @@
div(v-if='isMember') div(v-if='isMember')
button.btn.btn-danger(v-once, @click='leaveChallenge()') {{$t('leaveChallenge')}} button.btn.btn-danger(v-once, @click='leaveChallenge()') {{$t('leaveChallenge')}}
div(v-if='isLeader') div(v-if='isLeader')
button.btn.btn-success(v-once) {{$t('addTask')}} b-dropdown(:text="$t('create')")
b-dropdown-item(v-for="type in columns", :key="type", @click="createTask(type)")
| {{$t(type)}}
//- button.btn.btn-success(v-once) {{$t('addTask')}}
task-modal(
:task="workingTask",
:purpose="taskFormPurpose",
@cancel="cancelTaskModal()",
ref="taskModal",
:challengeId="challengeId",
v-on:taskCreated='taskCreated',
v-on:taskEdited='taskEdited',
)
div(v-if='isLeader') div(v-if='isLeader')
button.btn.btn-secondary(v-once, @click='edit()') {{$t('editChallenge')}} button.btn.btn-secondary(v-once, @click='edit()') {{$t('editChallenge')}}
div(v-if='isLeader') div(v-if='isLeader')
@@ -122,13 +139,20 @@
</style> </style>
<script> <script>
import Vue from 'vue';
import bDropdown from 'bootstrap-vue/lib/components/dropdown';
import bDropdownItem from 'bootstrap-vue/lib/components/dropdown-item';
import findIndex from 'lodash/findIndex'; import findIndex from 'lodash/findIndex';
import cloneDeep from 'lodash/cloneDeep';
import { mapState } from 'client/libs/store'; import { mapState } from 'client/libs/store';
import closeChallengeModal from './closeChallengeModal'; import closeChallengeModal from './closeChallengeModal';
import Column from '../tasks/column'; import Column from '../tasks/column';
import TaskModal from '../tasks/taskModal';
import challengeModal from './challengeModal'; import challengeModal from './challengeModal';
import taskDefaults from 'common/script/libs/taskDefaults';
import gemIcon from 'assets/svg/gem.svg'; import gemIcon from 'assets/svg/gem.svg';
import memberIcon from 'assets/svg/member-icon.svg'; import memberIcon from 'assets/svg/member-icon.svg';
import calendarIcon from 'assets/svg/calendar.svg'; import calendarIcon from 'assets/svg/calendar.svg';
@@ -139,6 +163,9 @@ export default {
closeChallengeModal, closeChallengeModal,
challengeModal, challengeModal,
TaskColumn: Column, TaskColumn: Column,
TaskModal,
bDropdown,
bDropdownItem,
}, },
data () { data () {
return { return {
@@ -150,6 +177,16 @@ export default {
}), }),
challenge: {}, challenge: {},
members: [], members: [],
tasksByType: {
habit: [],
daily: [],
todo: [],
reward: [],
},
editingTask: {},
creatingTask: {},
workingTask: {},
taskFormPurpose: 'create',
}; };
}, },
computed: { computed: {
@@ -165,8 +202,43 @@ export default {
async mounted () { async mounted () {
this.challenge = await this.$store.dispatch('challenges:getChallenge', {challengeId: this.challengeId}); this.challenge = await this.$store.dispatch('challenges:getChallenge', {challengeId: this.challengeId});
this.members = await this.$store.dispatch('members:getChallengeMembers', {challengeId: this.challengeId}); this.members = await this.$store.dispatch('members:getChallengeMembers', {challengeId: this.challengeId});
let tasks = await this.$store.dispatch('tasks:getChallengeTasks', {challengeId: this.challengeId});
tasks.forEach((task) => {
this.tasksByType[task.type].push(task);
});
}, },
methods: { methods: {
editTask (task) {
this.taskFormPurpose = 'edit';
this.editingTask = cloneDeep(task);
this.workingTask = this.editingTask;
// Necessary otherwise the first time the modal is not rendered
Vue.nextTick(() => {
this.$root.$emit('show::modal', 'task-modal');
});
},
createTask (type) {
this.taskFormPurpose = 'create';
this.creatingTask = taskDefaults({type, text: ''});
this.workingTask = this.editingTask;
// Necessary otherwise the first time the modal is not rendered
Vue.nextTick(() => {
this.$root.$emit('show::modal', 'task-modal');
});
},
cancelTaskModal () {
this.editingTask = null;
this.creatingTask = null;
},
taskCreated (task) {
this.tasksByType[task.type].push(task);
},
taskEdited (task) {
let index = findIndex(this.tasksByType[task.type], (taskItem) => {
return taskItem._id === task._id;
});
this.tasksByType[task.type].splice(index, 1, task);
},
showMemberModal () { showMemberModal () {
this.$store.state.viewingMembers = this.members; this.$store.state.viewingMembers = this.members;
this.$root.$emit('show::modal', 'members-modal'); this.$root.$emit('show::modal', 'members-modal');

View File

@@ -12,7 +12,7 @@
) {{ $t(filter.label) }} ) {{ $t(filter.label) }}
.tasks-list .tasks-list
task( task(
v-for="task in tasks[`${type}s`]", v-for="task in taskList",
:key="task.id", :task="task", :key="task.id", :task="task",
v-if="filterTask(task)", v-if="filterTask(task)",
@editTask="editTask", @editTask="editTask",
@@ -25,109 +25,109 @@
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '~client/assets/scss/colors.scss'; @import '~client/assets/scss/colors.scss';
.tasks-column { .tasks-column {
height: 556px; height: 556px;
}
.tasks-list {
border-radius: 4px;
background: $gray-600;
padding: 8px;
// not sure why but this is necessary or the last task will overflow the container
padding-bottom: 0.1px;
position: relative;
height: calc(100% - 64px);
overflow: auto;
}
.bottom-gradient {
position: absolute;
bottom: 0px;
left: 0px;
height: 42px;
background-image: linear-gradient(to bottom, rgba($gray-10, 0), rgba($gray-10, 0.24));
width: 100%;
z-index: 99;
}
.tasks-column-title {
margin-bottom: 8px;
}
.filters {
flex-grow: 1;
}
.filter {
font-weight: bold;
color: $gray-100;
font-style: normal;
padding: 8px;
cursor: pointer;
&:hover {
color: $purple-200;
} }
&.active { .tasks-list {
color: $purple-200; border-radius: 4px;
border-bottom: 2px solid $purple-200; background: $gray-600;
padding-bottom: 6px; padding: 8px;
} // not sure why but this is necessary or the last task will overflow the container
} padding-bottom: 0.1px;
position: relative;
.column-background { height: calc(100% - 64px);
position: absolute; overflow: auto;
bottom: 32px;
z-index: 7;
&.initial-description {
top: 30%;
} }
.svg-icon { .bottom-gradient {
margin: 0 auto; position: absolute;
margin-bottom: 12px; bottom: 0px;
left: 0px;
height: 42px;
background-image: linear-gradient(to bottom, rgba($gray-10, 0), rgba($gray-10, 0.24));
width: 100%;
z-index: 99;
} }
h3, .small-text { .tasks-column-title {
color: $gray-300; margin-bottom: 8px;
text-align: center;
} }
h3 { .filters {
font-weight: normal; flex-grow: 1;
margin-bottom: 4px;
} }
.small-text { .filter {
font-weight: bold;
color: $gray-100;
font-style: normal; font-style: normal;
padding-left: 24px; padding: 8px;
padding-right: 24px; cursor: pointer;
&:hover {
color: $purple-200;
}
&.active {
color: $purple-200;
border-bottom: 2px solid $purple-200;
padding-bottom: 6px;
}
} }
}
.icon-habit { .column-background {
width: 30px; position: absolute;
height: 20px; bottom: 32px;
} z-index: 7;
.icon-daily { &.initial-description {
width: 30px; top: 30%;
height: 20px; }
}
.icon-todo { .svg-icon {
width: 20px; margin: 0 auto;
height: 20px; margin-bottom: 12px;
} }
.icon-reward { h3, .small-text {
width: 26px; color: $gray-300;
height: 20px; text-align: center;
} }
h3 {
font-weight: normal;
margin-bottom: 4px;
}
.small-text {
font-style: normal;
padding-left: 24px;
padding-right: 24px;
}
}
.icon-habit {
width: 30px;
height: 20px;
}
.icon-daily {
width: 30px;
height: 20px;
}
.icon-todo {
width: 20px;
height: 20px;
}
.icon-reward {
width: 26px;
height: 20px;
}
</style> </style>
<script> <script>
@@ -145,7 +145,7 @@ export default {
Task, Task,
bModal, bModal,
}, },
props: ['type', 'isUser', 'searchText', 'selectedTags'], props: ['type', 'isUser', 'searchText', 'selectedTags', 'taskListOverride'],
data () { data () {
const types = Object.freeze({ const types = Object.freeze({
habit: { habit: {
@@ -201,6 +201,10 @@ export default {
tasks: 'tasks.data', tasks: 'tasks.data',
userPreferences: 'user.data.preferences', userPreferences: 'user.data.preferences',
}), }),
taskList () {
if (this.taskListOverride) return this.taskListOverride;
return this.tasks[`${this.type}s`];
},
}, },
methods: { methods: {
...mapActions({loadCompletedTodos: 'tasks:fetchCompletedTodos'}), ...mapActions({loadCompletedTodos: 'tasks:fetchCompletedTodos'}),
@@ -220,7 +224,7 @@ export default {
// Tags // Tags
const selectedTags = this.selectedTags; const selectedTags = this.selectedTags;
if (selectedTags.length > 0) { if (selectedTags && selectedTags.length > 0) {
const hasSelectedTag = task.tags.find(tagId => { const hasSelectedTag = task.tags.find(tagId => {
return selectedTags.indexOf(tagId) !== -1; return selectedTags.indexOf(tagId) !== -1;
}); });

View File

@@ -98,7 +98,7 @@ form(
.option .option
label(v-once) {{ $t('tags') }} label(v-once) {{ $t('tags') }}
.category-wrap(@click="showTagsSelect = !showTagsSelect") .category-wrap(@click="showTagsSelect = !showTagsSelect")
span.category-select(v-if='task.tags.length === 0') {{$t('none')}} span.category-select(v-if='task.tags && task.tags.length === 0') {{$t('none')}}
span.category-select(v-else) {{getTagsFor(task)[0]}} span.category-select(v-else) {{getTagsFor(task)[0]}}
.category-box(v-if="showTagsSelect") .category-box(v-if="showTagsSelect")
.form-check( .form-check(
@@ -123,200 +123,200 @@ form(
</template> </template>
<style lang="scss"> <style lang="scss">
@import '~client/assets/scss/colors.scss'; @import '~client/assets/scss/colors.scss';
#task-modal { #task-modal {
.modal-dialog.modal-sm { .modal-dialog.modal-sm {
max-width: 448px; max-width: 448px;
}
label {
font-weight: bold;
}
input, textarea {
border: none;
background-color: rgba(0, 0, 0, 0.16);
&:focus {
color: $white !important;
} }
}
.modal-content { label {
border-radius: 8px; font-weight: bold;
border: none;
}
.modal-header, .modal-body, .modal-footer {
padding: 0px;
border: none;
}
.task-modal-content, .task-modal-header {
padding-left: 23px;
padding-right: 23px;
}
.task-modal-header {
color: $white;
width: 100%;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
padding-top: 16px;
padding-bottom: 24px;
h1 {
color: $white;
} }
}
.task-modal-content { input, textarea {
padding-top: 24px; border: none;
background-color: rgba(0, 0, 0, 0.16);
input {
background: $white;
border: 1px solid $gray-500;
color: $gray-200;
&:focus { &:focus {
color: $gray-50 !important;
}
}
}
.info-icon {
float: left;
height: 16px;
width: 16px;
margin-left: 8px;
margin-top: 2px;
}
.difficulty-trivial-icon {
width: 16px;
height: 16px;
}
.difficulty-normal-icon {
width: 36px;
height: 16px;
}
.difficulty-medium-icon {
width: 36px;
height: 32px;
}
.difficulty-hard-icon {
width: 36px;
height: 36px;
}
.option {
margin-bottom: 12px;
margin-top: 12px;
position: relative;
}
.option-item {
margin-right: 48px;
cursor: pointer;
&:last-child {
margin-right: 0px;
}
&-box {
width: 64px;
height: 64px;
border-radius: 2px;
background: $gray-600;
margin-bottom: 8px;
display: flex;
align-items: center;
justify-content: center;
.habit-control.task-habit-disabled-control-habit {
color: $white !important; color: $white !important;
border: none;
background: $gray-300;
} }
} }
&-label { .modal-content {
color: $gray-50; border-radius: 8px;
text-align: center; border: none;
}
}
.category-wrap {
cursor: pointer;
margin-top: 0px;
}
.category-box {
bottom: 0px;
left: 40px;
top: auto;
}
.checklist-group {
border-top: 1px solid $gray-500;
.input-group-btn {
cursor: pointer;
padding-left: 10px;
padding-right: 10px;
} }
.destroy-icon { .modal-header, .modal-body, .modal-footer {
width: 14px; padding: 0px;
border: none;
}
.task-modal-content, .task-modal-header {
padding-left: 23px;
padding-right: 23px;
}
.task-modal-header {
color: $white;
width: 100%;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
padding-top: 16px;
padding-bottom: 24px;
h1 {
color: $white;
}
}
.task-modal-content {
padding-top: 24px;
input {
background: $white;
border: 1px solid $gray-500;
color: $gray-200;
&:focus {
color: $gray-50 !important;
}
}
}
.info-icon {
float: left;
height: 16px;
width: 16px;
margin-left: 8px;
margin-top: 2px;
}
.difficulty-trivial-icon {
width: 16px;
height: 16px; height: 16px;
} }
}
.checklist-item { .difficulty-normal-icon {
margin-bottom: 0px; width: 36px;
border-radius: 0px; height: 16px;
border: none !important;
padding-left: 36px;
&:last-child {
background-size: 10px 10px;
background-image: url(~client/assets/svg/for-css/positive.svg);
background-repeat: no-repeat;
background-position: center left 10px;
border-top: 1px solid $gray-500 !important;
border-bottom: 1px solid $gray-500 !important;
} }
}
.task-modal-footer { .difficulty-medium-icon {
margin: 0 auto; width: 36px;
padding-bottom: 24px; height: 32px;
border-top-left-radius: 8px; }
border-top-right-radius: 8px;
margin-top: 50px;
.delete-task-btn, .cancel-task-btn { .difficulty-hard-icon {
margin-left: 16px; width: 36px;
height: 36px;
}
.option {
margin-bottom: 12px;
margin-top: 12px;
position: relative;
}
.option-item {
margin-right: 48px;
cursor: pointer; cursor: pointer;
&:hover, &:focus, &:active { &:last-child {
text-decoration: underline; margin-right: 0px;
}
&-box {
width: 64px;
height: 64px;
border-radius: 2px;
background: $gray-600;
margin-bottom: 8px;
display: flex;
align-items: center;
justify-content: center;
.habit-control.task-habit-disabled-control-habit {
color: $white !important;
border: none;
background: $gray-300;
}
}
&-label {
color: $gray-50;
text-align: center;
} }
} }
.delete-task-btn { .category-wrap {
color: $red-50; cursor: pointer;
margin-top: 0px;
} }
.cancel-task-btn { .category-box {
color: $blue-10; bottom: 0px;
left: 40px;
top: auto;
}
.checklist-group {
border-top: 1px solid $gray-500;
.input-group-btn {
cursor: pointer;
padding-left: 10px;
padding-right: 10px;
}
.destroy-icon {
width: 14px;
height: 16px;
}
}
.checklist-item {
margin-bottom: 0px;
border-radius: 0px;
border: none !important;
padding-left: 36px;
&:last-child {
background-size: 10px 10px;
background-image: url(~client/assets/svg/for-css/positive.svg);
background-repeat: no-repeat;
background-position: center left 10px;
border-top: 1px solid $gray-500 !important;
border-bottom: 1px solid $gray-500 !important;
}
}
.task-modal-footer {
margin: 0 auto;
padding-bottom: 24px;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
margin-top: 50px;
.delete-task-btn, .cancel-task-btn {
margin-left: 16px;
cursor: pointer;
&:hover, &:focus, &:active {
text-decoration: underline;
}
}
.delete-task-btn {
color: $red-50;
}
.cancel-task-btn {
color: $blue-10;
}
} }
} }
}
</style> </style>
<script> <script>
@@ -343,7 +343,7 @@ export default {
bDropdownItem, bDropdownItem,
Datepicker, Datepicker,
}, },
props: ['task', 'purpose'], // purpose is either create or edit, task is the task created or edited props: ['task', 'purpose', 'challengeId'], // purpose is either create or edit, task is the task created or edited
data () { data () {
return { return {
showTagsSelect: false, showTagsSelect: false,
@@ -438,9 +438,18 @@ export default {
}, },
submit () { submit () {
if (this.purpose === 'create') { if (this.purpose === 'create') {
this.createTask(this.task); if (this.challengeId) {
this.$store.dispatch('tasks:createChallengeTasks', {
challengeId: this.challengeId,
tasks: [this.task],
});
this.$emit('taskCreated', this.task);
} else {
this.createTask(this.task);
}
} else { } else {
this.saveTask(this.task); this.saveTask(this.task);
this.$emit('taskEdited', this.task);
} }
this.$root.$emit('hide::modal', 'task-modal'); this.$root.$emit('hide::modal', 'task-modal');
}, },

View File

@@ -62,115 +62,115 @@
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '~client/assets/scss/colors.scss'; @import '~client/assets/scss/colors.scss';
.user-tasks-page { .user-tasks-page {
padding-top: 31px; padding-top: 31px;
}
.tasks-navigation {
margin-bottom: 40px;
}
.positive {
display: inline-block;
width: 10px;
color: $green-500;
margin-right: 8px;
padding-top: 6px;
}
button.btn.btn-secondary.filter-button {
box-shadow: none;
border-radius: 2px;
border: 1px solid $gray-400 !important;
&:hover, &:active, &:focus, &.open {
box-shadow: none;
border-color: $purple-500 !important;
color: $gray-50 !important;
} }
&.filter-button-open { .tasks-navigation {
color: $purple-200 !important; margin-bottom: 40px;
}
.positive {
display: inline-block;
width: 10px;
color: $green-500;
margin-right: 8px;
padding-top: 6px;
}
button.btn.btn-secondary.filter-button {
box-shadow: none;
border-radius: 2px;
border: 1px solid $gray-400 !important;
&:hover, &:active, &:focus, &.open {
box-shadow: none;
border-color: $purple-500 !important;
color: $gray-50 !important;
}
&.filter-button-open {
color: $purple-200 !important;
.filter-icon {
color: $purple-200 !important;
}
}
.filter-icon { .filter-icon {
color: $purple-200 !important; height: 10px;
width: 12px;
color: $gray-50;
margin-left: 15px;
} }
} }
.filter-icon { .filter-panel {
height: 10px; position: absolute;
width: 12px; padding-left: 24px;
color: $gray-50; padding-right: 24px;
margin-left: 15px; max-width: 40vw;
} z-index: 9999;
} background: $white;
border-radius: 2px;
box-shadow: 0 2px 2px 0 rgba($black, 0.16), 0 1px 4px 0 rgba($black, 0.12);
top: 44px;
left: 20vw;
font-size: 14px;
line-height: 1.43;
text-overflow: ellipsis;
.filter-panel { .tags-category {
position: absolute; border-bottom: 1px solid $gray-600;
padding-left: 24px; padding-bottom: 24px;
padding-right: 24px; padding-top: 24px;
max-width: 40vw;
z-index: 9999;
background: $white;
border-radius: 2px;
box-shadow: 0 2px 2px 0 rgba($black, 0.16), 0 1px 4px 0 rgba($black, 0.12);
top: 44px;
left: 20vw;
font-size: 14px;
line-height: 1.43;
text-overflow: ellipsis;
.tags-category {
border-bottom: 1px solid $gray-600;
padding-bottom: 24px;
padding-top: 24px;
}
.tags-header {
flex-basis: 96px;
flex-shrink: 0;
a {
font-size: 12px;
line-height: 1.33;
color: $blue-10;
margin-top: 4px;
&:focus, &:hover, &:active {
text-decoration: underline;
}
} }
}
.custom-control-description { .tags-header {
margin-left: 10px; flex-basis: 96px;
} flex-shrink: 0;
.filter-panel-footer { a {
padding-top: 16px; font-size: 12px;
padding-bottom: 16px; line-height: 1.33;
color: $blue-10;
margin-top: 4px;
a { &:focus, &:hover, &:active {
&:focus, &:hover, &:active { text-decoration: underline;
text-decoration: underline; }
} }
} }
.reset-filters { .custom-control-description {
color: $red-50; margin-left: 10px;
} }
.apply-filters { .filter-panel-footer {
color: $blue-10; padding-top: 16px;
} padding-bottom: 16px;
.cancel-filters { a {
color: $gray-300; &:focus, &:hover, &:active {
text-decoration: underline;
}
}
.reset-filters {
color: $red-50;
}
.apply-filters {
color: $blue-10;
}
.cancel-filters {
color: $gray-300;
}
} }
} }
}
</style> </style>
<script> <script>

View File

@@ -112,11 +112,11 @@ export async function save (store, editedTask) {
sanitizeChecklist(editedTask); sanitizeChecklist(editedTask);
Object.assign(originalTask, editedTask); if (originalTask) Object.assign(originalTask, editedTask);
const taskDataToSend = omit(originalTask, ['history']); const taskDataToSend = omit(editedTask, ['history']);
const response = await axios.put(`/api/v3/tasks/${originalTask._id}`, taskDataToSend); const response = await axios.put(`/api/v3/tasks/${editedTask._id}`, taskDataToSend);
Object.assign(originalTask, response.data.data); if (originalTask) Object.assign(originalTask, response.data.data);
} }
export async function destroy (store, task) { export async function destroy (store, task) {
@@ -129,3 +129,13 @@ export async function destroy (store, task) {
await axios.delete(`/api/v3/tasks/${task._id}`); await axios.delete(`/api/v3/tasks/${task._id}`);
} }
export async function getChallengeTasks (store, payload) {
let response = await axios.get(`/api/v3/tasks/challenge/${payload.challengeId}`);
return response.data.data;
}
export async function createChallengeTasks (store, payload) {
let response = await axios.post(`/api/v3/tasks/challenge/${payload.challengeId}`, payload.tasks);
return response.data.data;
}

View File

@@ -3,7 +3,7 @@ import { shouldDo } from 'common/script/cron';
// Return all the tags belonging to an user task // Return all the tags belonging to an user task
export function getTagsFor (store) { export function getTagsFor (store) {
return (task) => store.state.user.data.tags return (task) => store.state.user.data.tags
.filter(tag => task.tags.indexOf(tag.id) !== -1) .filter(tag => task.tags && task.tags.indexOf(tag.id) !== -1)
.map(tag => tag.name); .map(tag => tag.name);
} }