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 () {
let tweet = this.$t('levelUpShare');
return {
statsAllocationBoxIsOpen: true,
maxHealth,
tweet,
socialLevelLink: `${BASE_URL}/social/level-up`,

View File

@@ -26,7 +26,12 @@
| {{challenge.prize}}
.details(v-once) {{$t('prize')}}
.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
.acitons
div(v-if='!isMember && !isLeader')
@@ -34,7 +39,19 @@
div(v-if='isMember')
button.btn.btn-danger(v-once, @click='leaveChallenge()') {{$t('leaveChallenge')}}
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')
button.btn.btn-secondary(v-once, @click='edit()') {{$t('editChallenge')}}
div(v-if='isLeader')
@@ -122,13 +139,20 @@
</style>
<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 cloneDeep from 'lodash/cloneDeep';
import { mapState } from 'client/libs/store';
import closeChallengeModal from './closeChallengeModal';
import Column from '../tasks/column';
import TaskModal from '../tasks/taskModal';
import challengeModal from './challengeModal';
import taskDefaults from 'common/script/libs/taskDefaults';
import gemIcon from 'assets/svg/gem.svg';
import memberIcon from 'assets/svg/member-icon.svg';
import calendarIcon from 'assets/svg/calendar.svg';
@@ -139,6 +163,9 @@ export default {
closeChallengeModal,
challengeModal,
TaskColumn: Column,
TaskModal,
bDropdown,
bDropdownItem,
},
data () {
return {
@@ -150,6 +177,16 @@ export default {
}),
challenge: {},
members: [],
tasksByType: {
habit: [],
daily: [],
todo: [],
reward: [],
},
editingTask: {},
creatingTask: {},
workingTask: {},
taskFormPurpose: 'create',
};
},
computed: {
@@ -165,8 +202,43 @@ export default {
async mounted () {
this.challenge = await this.$store.dispatch('challenges:getChallenge', {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: {
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 () {
this.$store.state.viewingMembers = this.members;
this.$root.$emit('show::modal', 'members-modal');

View File

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

View File

@@ -98,7 +98,7 @@ form(
.option
label(v-once) {{ $t('tags') }}
.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]}}
.category-box(v-if="showTagsSelect")
.form-check(
@@ -123,200 +123,200 @@ form(
</template>
<style lang="scss">
@import '~client/assets/scss/colors.scss';
@import '~client/assets/scss/colors.scss';
#task-modal {
.modal-dialog.modal-sm {
max-width: 448px;
}
label {
font-weight: bold;
}
input, textarea {
border: none;
background-color: rgba(0, 0, 0, 0.16);
&:focus {
color: $white !important;
#task-modal {
.modal-dialog.modal-sm {
max-width: 448px;
}
}
.modal-content {
border-radius: 8px;
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;
label {
font-weight: bold;
}
}
.task-modal-content {
padding-top: 24px;
input {
background: $white;
border: 1px solid $gray-500;
color: $gray-200;
input, textarea {
border: none;
background-color: rgba(0, 0, 0, 0.16);
&: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;
border: none;
background: $gray-300;
}
}
&-label {
color: $gray-50;
text-align: center;
}
}
.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;
.modal-content {
border-radius: 8px;
border: none;
}
.destroy-icon {
width: 14px;
.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 {
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;
}
}
.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;
.difficulty-normal-icon {
width: 36px;
height: 16px;
}
}
.task-modal-footer {
margin: 0 auto;
padding-bottom: 24px;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
margin-top: 50px;
.difficulty-medium-icon {
width: 36px;
height: 32px;
}
.delete-task-btn, .cancel-task-btn {
margin-left: 16px;
.difficulty-hard-icon {
width: 36px;
height: 36px;
}
.option {
margin-bottom: 12px;
margin-top: 12px;
position: relative;
}
.option-item {
margin-right: 48px;
cursor: pointer;
&:hover, &:focus, &:active {
text-decoration: underline;
&: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;
border: none;
background: $gray-300;
}
}
&-label {
color: $gray-50;
text-align: center;
}
}
.delete-task-btn {
color: $red-50;
.category-wrap {
cursor: pointer;
margin-top: 0px;
}
.cancel-task-btn {
color: $blue-10;
.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 {
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>
<script>
@@ -343,7 +343,7 @@ export default {
bDropdownItem,
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 () {
return {
showTagsSelect: false,
@@ -438,9 +438,18 @@ export default {
},
submit () {
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 {
this.saveTask(this.task);
this.$emit('taskEdited', this.task);
}
this.$root.$emit('hide::modal', 'task-modal');
},

View File

@@ -62,115 +62,115 @@
</template>
<style lang="scss" scoped>
@import '~client/assets/scss/colors.scss';
@import '~client/assets/scss/colors.scss';
.user-tasks-page {
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;
.user-tasks-page {
padding-top: 31px;
}
&.filter-button-open {
color: $purple-200 !important;
.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 {
color: $purple-200 !important;
.filter-icon {
color: $purple-200 !important;
}
}
.filter-icon {
color: $purple-200 !important;
height: 10px;
width: 12px;
color: $gray-50;
margin-left: 15px;
}
}
.filter-icon {
height: 10px;
width: 12px;
color: $gray-50;
margin-left: 15px;
}
}
.filter-panel {
position: absolute;
padding-left: 24px;
padding-right: 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;
.filter-panel {
position: absolute;
padding-left: 24px;
padding-right: 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;
}
.tags-category {
border-bottom: 1px solid $gray-600;
padding-bottom: 24px;
padding-top: 24px;
}
}
.custom-control-description {
margin-left: 10px;
}
.tags-header {
flex-basis: 96px;
flex-shrink: 0;
.filter-panel-footer {
padding-top: 16px;
padding-bottom: 16px;
a {
font-size: 12px;
line-height: 1.33;
color: $blue-10;
margin-top: 4px;
a {
&:focus, &:hover, &:active {
text-decoration: underline;
&:focus, &:hover, &:active {
text-decoration: underline;
}
}
}
.reset-filters {
color: $red-50;
.custom-control-description {
margin-left: 10px;
}
.apply-filters {
color: $blue-10;
}
.filter-panel-footer {
padding-top: 16px;
padding-bottom: 16px;
.cancel-filters {
color: $gray-300;
a {
&:focus, &:hover, &:active {
text-decoration: underline;
}
}
.reset-filters {
color: $red-50;
}
.apply-filters {
color: $blue-10;
}
.cancel-filters {
color: $gray-300;
}
}
}
}
</style>
<script>

View File

@@ -112,11 +112,11 @@ export async function save (store, editedTask) {
sanitizeChecklist(editedTask);
Object.assign(originalTask, editedTask);
if (originalTask) Object.assign(originalTask, editedTask);
const taskDataToSend = omit(originalTask, ['history']);
const response = await axios.put(`/api/v3/tasks/${originalTask._id}`, taskDataToSend);
Object.assign(originalTask, response.data.data);
const taskDataToSend = omit(editedTask, ['history']);
const response = await axios.put(`/api/v3/tasks/${editedTask._id}`, taskDataToSend);
if (originalTask) Object.assign(originalTask, response.data.data);
}
export async function destroy (store, task) {
@@ -129,3 +129,13 @@ export async function destroy (store, task) {
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
export function getTagsFor (store) {
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);
}