feat(teams): user preference toggle for mirroring

This commit is contained in:
SabreCat
2022-06-28 16:18:24 -05:00
parent 712b85ce84
commit a3f61306d3
5 changed files with 62 additions and 18 deletions

View File

@@ -41,7 +41,7 @@
&-modal {
&-bg { background: $maroon-100 !important; }
&-headings { color: $white; }
&-headings { color: $white !important; }
&-icon { color: $maroon-100 !important; }
&-text { color: $red-1 !important; }
&-content {

View File

@@ -28,8 +28,16 @@
>
</div>
<div
class="create-task-area ml-auto d-flex align-items-top"
class="create-task-area ml-auto d-flex align-items-center"
>
<toggle-switch
id="taskMirrorToggle"
class="mr-3 mb-1"
:label="'Copy tasks'"
:checked="user.preferences.tasks.mirrorGroupTasks"
:hover-text="'Add assigned and open tasks to your personal task board'"
@change="changeMirrorPreference"
/>
<div
class="day-start mb-auto d-flex align-items-center"
v-html="$t('dayStart', { startTime: groupStartTime } )"
@@ -94,6 +102,24 @@
</div>
</template>
<style lang="scss">
#taskMirrorToggle {
font-weight: bold;
.svg-icon {
margin: 3px 6px 0px 4px;
}
.toggle-switch {
margin-left: 0px;
}
.toggle-switch-description {
margin-top: 3px;
}
}
</style>
<style lang="scss" scoped>
@import '~@/assets/scss/colors.scss';
@import '~@/assets/scss/create-task.scss';
@@ -133,6 +159,9 @@ import taskDefaults from '@/../../common/script/libs/taskDefaults';
import TaskColumn from '../tasks/column';
import TaskModal from '../tasks/taskModal';
import GroupPlanOverviewModal from './groupPlanOverviewModal';
import toggleSwitch from '@/components/ui/toggleSwitch';
import sync from '../../mixins/sync';
import positiveIcon from '@/assets/svg/positive.svg';
import filterIcon from '@/assets/svg/filter.svg';
@@ -149,7 +178,9 @@ export default {
TaskColumn,
TaskModal,
GroupPlanOverviewModal,
toggleSwitch,
},
mixins: [sync],
props: ['groupId'],
data () {
return {
@@ -239,6 +270,10 @@ export default {
this.$set(this, 'searchId', to.params.groupId);
next();
},
async beforeRouteLeave (to, from, next) {
await this.sync();
next();
},
mounted () {
if (!this.searchId) this.searchId = this.groupId;
this.load();
@@ -369,6 +404,11 @@ export default {
if (this.temporarilySelectedTags.indexOf(tagId) !== -1) return true;
return false;
},
changeMirrorPreference (newVal) {
this.$store.dispatch('user:set', {
'preferences.tasks.mirrorGroupTasks': newVal,
});
},
},
};
</script>

View File

@@ -1164,8 +1164,9 @@ export default {
if (
this.isGroupTask && direction === 'down'
&& ['todo', 'daily'].indexOf(this.task.type) !== -1
&& (!this.task.group.assignedUsersDetail
|| !this.task.group.assignedUsersDetail[this.user._id])
&& !((this.task.group.completedBy && this.task.group.completedBy.userId === this.user._id)
|| (this.task.group.assignedUsersDetail
&& this.task.group.assignedUsersDetail[this.user._id]))
) {
this.$store.dispatch('tasks:needsWork', {
taskId: this.task._id,

View File

@@ -157,7 +157,7 @@ async function getTasks (req, res, options = {}) {
let query;
let limit;
let sort;
let upgradedGroups;
let upgradedGroups = [];
const owner = group || challenge || user;
if (challenge) {
@@ -165,18 +165,20 @@ async function getTasks (req, res, options = {}) {
} else if (group) {
query = { 'group.id': group._id };
} else {
upgradedGroups = await Group.find(
{
_id: { $in: user.guilds.concat(user.party._id) },
'purchased.plan.customerId': { $exists: true },
$or: [
{ 'purchased.plan.dateTerminated': { $exists: false } },
{ 'purchased.plan.dateTerminated': null },
{ 'purchased.plan.dateTerminated': { $gt: new Date() } },
],
},
{ _id: 1 },
).exec();
if (user.preferences.tasks.mirrorGroupTasks) {
upgradedGroups = await Group.find(
{
_id: { $in: user.guilds.concat(user.party._id) },
'purchased.plan.customerId': { $exists: true },
$or: [
{ 'purchased.plan.dateTerminated': { $exists: false } },
{ 'purchased.plan.dateTerminated': null },
{ 'purchased.plan.dateTerminated': { $gt: new Date() } },
],
},
{ _id: 1 },
).exec();
}
if (upgradedGroups.length > 0) {
const upgradedGroupIds = [];
for (const upgradedGroup of upgradedGroups) {
@@ -210,7 +212,7 @@ async function getTasks (req, res, options = {}) {
query.type = 'todo';
query.completed = true;
if (upgradedGroups && upgradedGroups.length > 0) {
if (upgradedGroups.length > 0) {
query.$or = [
{ userId: user._id },
{ 'group.assignedUsers': user._id },

View File

@@ -582,6 +582,7 @@ export default new Schema({
tasks: {
groupByChallenge: { $type: Boolean, default: false }, // @TODO remove? not used
confirmScoreNotes: { $type: Boolean, default: false }, // @TODO remove? not used
mirrorGroupTasks: { $type: Boolean, default: false },
},
improvementCategories: {
$type: Array,