Skip to content

Commit

Permalink
Recurrence selects
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Dec 20, 2016
1 parent 833d183 commit 87a1dc2
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 126 deletions.
26 changes: 0 additions & 26 deletions frontend/app/components/select-element.js

This file was deleted.

49 changes: 3 additions & 46 deletions frontend/app/components/task-details-form.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import Ember from 'ember';

import recurrenceOptions from 'frontend/models/recurrence-options';
import recurrenceMatchPositions from 'frontend/models/recurrence-match-positions';
import recurrenceMatchDays from 'frontend/models/recurrence-match-days';
import Task from 'frontend/models/task';

export default Ember.Component.extend({
i18n: Ember.inject.service(),
Expand All @@ -16,48 +13,8 @@ export default Ember.Component.extend({
return translations;
}.property('taskAttributes'),

recurrenceOptions: recurrenceOptions,
recurrenceMatchPositions: recurrenceMatchPositions,
recurrenceMatchDays: recurrenceMatchDays,
recurrenceMatchPositionId: Ember.computed('task.recurrenceMatch', {
get: function() {
return this.getRecurrencePositionId();
},
set: function(_key, value) {
let recurrenceMatch = `${ value } ${ this.getRecurrenceDayId() }`;
this.set('task.recurrenceMatch', recurrenceMatch);
}
}),
recurrenceMatchDayId: Ember.computed('task.recurrenceMatch', {
get: function() {
return this.getRecurrenceDayId();
},
set: function(_key, value) {
let recurrenceMatch = `${ this.getRecurrencePositionId() } ${ value }`;
this.set('task.recurrenceMatch', recurrenceMatch);
}
}),
getRecurrencePositionId: function() {
if(this.get('task.recurrenceMatch')) {
return this.recurrenceOptionAt(0);
} else {
return 0;
}
},
getRecurrenceDayId: function() {
if(this.get('task.recurrenceMatch')) {
return this.recurrenceOptionAt(1);
} else {
return 0;
}
},
recurrenceOptionAt: function(index) {
let option = this.get('task.recurrenceMatch').split(' ')[index];
return parseInt(option);
},
taskRecurreceIsMonthly: function() {
return this.get('task.recurrence') === 2;
}.property('task.recurrence'),
Task: Task,

actions: {
submitForm() {
return this.sendAction('formAction', this.task);
Expand Down
26 changes: 26 additions & 0 deletions frontend/app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ export default {
'subject': 'Subject',
'to': 'To:'
},
'recurrence': {
'montly': 'Every month',
'placeholder': 'Task is carried out...',
'weekly': 'Every week'
},
'recurrenceMatch': {
'day': {
'monday': 'Monday',
'tuesday': 'Tuesday',
'wednesday': 'Wednesday',
'thursday': 'Thursday',
'friday': 'Friday',
'saturday': 'Saturday',
'sunday': 'Sunday',
'placeholder': 'day of the week'
},
'position': {
'first': 'the first',
'second': 'the second',
'third': 'the third',
'fourth': 'the fourth',
'nextToLast': 'the next to last',
'last': 'the last',
'placeholder': 'at certain...'
}
},
'show': {
'notifications': {
'title': 'Notifications'
Expand Down
26 changes: 26 additions & 0 deletions frontend/app/locales/es/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ export default {
'subject': 'Asunto',
'to': 'Para'
},
'recurrence': {
'montly': 'Cada mes',
'placeholder': 'La tarea se lleva a cabo...',
'weekly': 'Cada semana'
},
'recurrenceMatch': {
'day': {
'monday': 'lunes',
'tuesday': 'martes',
'wednesday': 'miércoles',
'thursday': 'jueves',
'friday': 'viernes',
'saturday': 'sábado',
'sunday': 'domingo',
'placeholder': 'día de la semana'
},
'position': {
'first': 'el primer',
'second': 'el segundo',
'third': 'el tercer',
'fourth': 'el cuarto',
'nextToLast': 'el penúltimo',
'last': 'el último',
'placeholder': 'en tal...'
}
},
'show': {
'notifications': {
'title': 'Notificaciones'
Expand Down
13 changes: 13 additions & 0 deletions frontend/app/models/recurrence-match-day-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';

const options = [
Ember.Object.create({ value: 0, label: "sunday" }),
Ember.Object.create({ value: 1, label: "monday" }),
Ember.Object.create({ value: 2, label: "tuesday" }),
Ember.Object.create({ value: 3, label: "wednesday" }),
Ember.Object.create({ value: 4, label: "thursday" }),
Ember.Object.create({ value: 5, label: "friday" }),
Ember.Object.create({ value: 6, label: "saturday" })
];

export default options;
11 changes: 0 additions & 11 deletions frontend/app/models/recurrence-match-days.js

This file was deleted.

12 changes: 12 additions & 0 deletions frontend/app/models/recurrence-match-position-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';

const options = [
Ember.Object.create({ value: 0, label: "first" }),
Ember.Object.create({ value: 1, label: "second" }),
Ember.Object.create({ value: 2, label: "third" }),
Ember.Object.create({ value: 3, label: "fourth" }),
Ember.Object.create({ value: -2, label: "nextToLast" }),
Ember.Object.create({ value: -1, label: "last" })
];

export default options;
10 changes: 0 additions & 10 deletions frontend/app/models/recurrence-match-positions.js

This file was deleted.

13 changes: 8 additions & 5 deletions frontend/app/models/recurrence-options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Ember from 'ember';

export default [
Ember.Object.create({ value: 0, label: "Daily" }),
Ember.Object.create({ value: 1, label: "Weekly" }),
Ember.Object.create({ value: 2, label: "Montly" }),
Ember.Object.create({ value: 3, label: "Yearly" })
const options = [
// Recurrence is currently implemented for weeks and months
// Ember.Object.create({ value: 0, label: "daily" }),
Ember.Object.create({ value: 1, label: "weekly" }),
Ember.Object.create({ value: 2, label: "montly" })
// Ember.Object.create({ value: 3, label: "yearly" })
];

export default options;
105 changes: 102 additions & 3 deletions frontend/app/models/task.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,85 @@
import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
import recurrenceOptions from 'frontend/models/recurrence-options';
import recurrenceMatchPositionOptions from 'frontend/models/recurrence-match-position-options';
import recurrenceMatchDayOptions from 'frontend/models/recurrence-match-day-options';

const Task = DS.Model.extend({
title: DS.attr('string'),
recurrence: DS.attr('number'),
recurrenceMatch: DS.attr('string'),
description: DS.attr('string'),
notificationEmail: DS.attr('string'),
notificationSubject: DS.attr('string'),
notificationBody: DS.attr('string'),

// Relations
turns: DS.hasMany('turn'),

// Computed properties
recurrenceObject: Ember.computed('recurrence', {
get() {
return this.findOption('recurrence');
},
set(key, option) {
this.set('recurrence', option.value);

return this.findOption('recurrence');
}
}),
recurrenceMatchPosition: Ember.computed('recurrenceMatch', {
get() {
return this.recurrenceMatchAt(0);
},
set(key, value) {
let recurrenceMatch = `${ value } ${ this.get('recurrenceMatchDay') }`;

this.set('recurrenceMatch', recurrenceMatch);

return value;
}
}),
recurrenceMatchPositionObject: Ember.computed('recurrenceMatchPosition', {
get() {
return this.findOption('recurrenceMatchPosition');
},
set(key, option) {
this.set('recurrenceMatchPosition', option.value);

return this.findOption('recurrenceMatchPosition');
}
}),
recurrenceMatchDay: Ember.computed('recurrenceMatch', {
get() {
return this.recurrenceMatchAt(1);
},
set(key, value) {
let recurrenceMatch = `${ this.get('recurrenceMatchPosition') } ${ value }`;

this.set('recurrenceMatch', recurrenceMatch);

return value;
}
}),
recurrenceMatchDayObject: Ember.computed('recurrenceMatchDay', {
get() {
return this.findOption('recurrenceMatchDay');
},
set(key, option) {
this.set('recurrenceMatchDay', option.value);

return this.findOption('recurrenceMatchDay');
}
}),

recurreceIsMonthly: Ember.computed('recurrence', function() {
return this.get('recurrence') === 2;
}),

notificationEmpty: Ember.computed('notificationSubject', 'notificationBody', function () {
return ! (this.get('notificationSubject') || this.get('notificationBody'));
}),
turns: DS.hasMany('turn'),
turnsSorting: ['position'],
sortedTurns: Ember.computed.sort('turns', 'turnsSorting'),
responsibles: Ember.computed('sortedTurns', function() {
Expand All @@ -23,5 +90,37 @@ export default DS.Model.extend({
} else {
return null;
}
})
}),

// Helper functions

/*
* Finds the option from recurrenceOptions, recurrenceMatchPositionOptions,
* recurrenceMatchDayOptions that matches value
*
* Defaults to current value
*/
findOption: function(name, value = this.get(name)) {
return Task.findOption(name, value);
},
recurrenceMatchAt: function(index) {
var value = this.get('recurrenceMatch').split(' ')[index];

return parseInt(value);
},
});

Task.reopenClass({
// Options
recurrenceOptions: recurrenceOptions,
recurrenceMatchPositionOptions: recurrenceMatchPositionOptions,
recurrenceMatchDayOptions: recurrenceMatchDayOptions,

findOption: function(name, value) {
var property = name + 'Options';

return this[property].find(opt => opt.value === value);
}
});

export default Task;
5 changes: 0 additions & 5 deletions frontend/app/templates/components/select-element.hbs

This file was deleted.

Loading

0 comments on commit 87a1dc2

Please sign in to comment.