Loading js/app/filters/reminderfilter.js +115 −26 Original line number Diff line number Diff line Loading @@ -24,22 +24,6 @@ app.filter('simpleReminderDescription', function() { 'use strict'; var actionMapper = { AUDIO: t('calendar', 'Audio alarm'), DISPLAY: t('calendar', 'Pop-up'), EMAIL: t('calendar', 'Email'), NONE: t('calendar', 'None') }; function getActionName(alarm) { var name = alarm.action.value; if (name && actionMapper.hasOwnProperty(name)) { return actionMapper[name]; } else { return name; } } return function(alarm) { if (typeof alarm !== 'object' || !alarm || typeof alarm.trigger !== 'object' || !alarm.trigger) { return ''; Loading @@ -51,29 +35,134 @@ app.filter('simpleReminderDescription', function() { var timeString = moment.duration(Math.abs(alarm.trigger.value), 'seconds').humanize(); if (alarm.trigger.value < 0) { if (relatedToStart) { return t('calendar', '{type} {time} before the event starts', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} before the event starts', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} before the event starts', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} before the event starts', {time: timeString}); case 'NONE': return t('calendar', 'None {time} before the event starts', {time: timeString}); default: return t('calendar', '{type} {time} before the event starts', {type: alarm.action.value, time: timeString}); } } else { return t('calendar', '{type} {time} before the event ends', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} before the event ends', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} before the event ends', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} before the event ends', {time: timeString}); case 'NONE': return t('calendar', 'None {time} before the event ends', {time: timeString}); default: return t('calendar', '{type} {time} before the event ends', {type: alarm.action.value, time: timeString}); } } } else if (alarm.trigger.value > 0) { if (relatedToStart) { return t('calendar', '{type} {time} after the event starts', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} after the event starts', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} after the event starts', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} after the event starts', {time: timeString}); case 'NONE': return t('calendar', 'None {time} after the event starts', {time: timeString}); default: return t('calendar', '{type} {time} after the event starts', {type: alarm.action.value, time: timeString}); } } else { return t('calendar', '{type} {time} after the event ends', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} after the event ends', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} after the event ends', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} after the event ends', {time: timeString}); case 'NONE': return t('calendar', 'None {time} after the event ends', {time: timeString}); default: return t('calendar', '{type} {time} after the event ends', {type: alarm.action.value, time: timeString}); } } } else { if (relatedToStart) { return t('calendar', '{type} at the event\'s start', {type: getActionName(alarm)}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm at the event\'s start'); case 'DISPLAY': return t('calendar', 'Pop-up at the event\'s start'); case 'EMAIL': return t('calendar', 'Email at the event\'s start'); case 'NONE': return t('calendar', 'None at the event\'s start'); default: return t('calendar', '{type} at the event\'s start', {type: alarm.action.value}); } } else { return t('calendar', '{type} at the event\'s end', {type: getActionName(alarm)}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm at the event\'s end'); case 'DISPLAY': return t('calendar', 'Pop-up at the event\'s end'); case 'EMAIL': return t('calendar', 'Email at the event\'s end'); case 'NONE': return t('calendar', 'None at the event\'s end'); default: return t('calendar', '{type} at the event\'s end', {type: alarm.action.value}); } } } } else { if (alarm.editor && moment.isMoment(alarm.editor.absMoment)) { switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm at {time}', {time: alarm.editor.absMoment.format('LLLL')}); case 'DISPLAY': return t('calendar', 'Pop-up at {time}', {time: alarm.editor.absMoment.format('LLLL')}); case 'EMAIL': return t('calendar', 'Email at {time}', {time: alarm.editor.absMoment.format('LLLL')}); case 'NONE': return t('calendar', 'None at {time}', {time: alarm.editor.absMoment.format('LLLL')}); default: return t('calendar', '{type} at {time}', { type: getActionName(alarm), type: alarm.action.value, time: alarm.editor.absMoment.format('LLLL') }); } } else { return ''; } Loading tests/js/unit/filters/reminderFilterSpec.js +22 −22 Original line number Diff line number Diff line Loading @@ -33,8 +33,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} before the event starts', { time: '15 minutes' }); }); it('should display email alarms correctly', function() { Loading @@ -52,8 +52,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Email', time: '15 minutes' }); })).toEqual('Email {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Email {time} before the event starts', { time: '15 minutes' }); }); it('should display popup alarms correctly', function() { Loading @@ -71,8 +71,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Pop-up', time: '15 minutes' }); })).toEqual('Pop-up {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Pop-up {time} before the event starts', { time: '15 minutes' }); }); it('should display none alarms correctly', function() { Loading @@ -90,8 +90,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'None', time: '15 minutes' }); })).toEqual('None {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'None {time} before the event starts', { time: '15 minutes' }); }); it('should display unknown alarms with it\'s identifier', function() { Loading Loading @@ -128,8 +128,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} before the event starts', { time: '15 minutes' }); }); it('should display alarms correctly (relative before end)', function() { Loading @@ -147,8 +147,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event ends', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} before the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} before the event ends', { time: '15 minutes' }); }); it('should display alarms correctly (relative at start)', function() { Loading @@ -166,8 +166,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 0 } })).toEqual('{type} at the event\'s start'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} at the event\'s start', { type: 'Audio alarm'}); })).toEqual('Audio alarm at the event\'s start'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm at the event\'s start'); }); it('should display alarms correctly (relative at end)', function() { Loading @@ -185,8 +185,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 0 } })).toEqual('{type} at the event\'s end'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} at the event\'s end', { type: 'Audio alarm'}); })).toEqual('Audio alarm at the event\'s end'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm at the event\'s end'); }); it('should display alarms correctly (relative after start)', function() { Loading @@ -204,8 +204,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 900 } })).toEqual('{type} {time} after the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} after the event starts', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} after the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} after the event starts', { time: '15 minutes' }); }); it('should display alarms correctly (relative after end)', function() { Loading @@ -223,8 +223,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 900 } })).toEqual('{type} {time} after the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} after the event ends', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} after the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} after the event ends', { time: '15 minutes' }); }); it('should display alarms correctly (absolute)', function() { Loading @@ -244,8 +244,8 @@ describe('The simpleReminderDescription filter', function () { type: 'date-time', value: moment('2013-02-08 09:30') } })).toEqual('{type} at {time}'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} at {time}', { type: 'Audio alarm', time: 'Friday, February 8, 2013 9:30 AM' }); })).toEqual('Audio alarm at {time}'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm at {time}', { time: 'Friday, February 8, 2013 9:30 AM' }); }); it('should return empty string when editor is not set for absolute alarms', function() { Loading Loading
js/app/filters/reminderfilter.js +115 −26 Original line number Diff line number Diff line Loading @@ -24,22 +24,6 @@ app.filter('simpleReminderDescription', function() { 'use strict'; var actionMapper = { AUDIO: t('calendar', 'Audio alarm'), DISPLAY: t('calendar', 'Pop-up'), EMAIL: t('calendar', 'Email'), NONE: t('calendar', 'None') }; function getActionName(alarm) { var name = alarm.action.value; if (name && actionMapper.hasOwnProperty(name)) { return actionMapper[name]; } else { return name; } } return function(alarm) { if (typeof alarm !== 'object' || !alarm || typeof alarm.trigger !== 'object' || !alarm.trigger) { return ''; Loading @@ -51,29 +35,134 @@ app.filter('simpleReminderDescription', function() { var timeString = moment.duration(Math.abs(alarm.trigger.value), 'seconds').humanize(); if (alarm.trigger.value < 0) { if (relatedToStart) { return t('calendar', '{type} {time} before the event starts', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} before the event starts', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} before the event starts', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} before the event starts', {time: timeString}); case 'NONE': return t('calendar', 'None {time} before the event starts', {time: timeString}); default: return t('calendar', '{type} {time} before the event starts', {type: alarm.action.value, time: timeString}); } } else { return t('calendar', '{type} {time} before the event ends', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} before the event ends', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} before the event ends', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} before the event ends', {time: timeString}); case 'NONE': return t('calendar', 'None {time} before the event ends', {time: timeString}); default: return t('calendar', '{type} {time} before the event ends', {type: alarm.action.value, time: timeString}); } } } else if (alarm.trigger.value > 0) { if (relatedToStart) { return t('calendar', '{type} {time} after the event starts', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} after the event starts', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} after the event starts', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} after the event starts', {time: timeString}); case 'NONE': return t('calendar', 'None {time} after the event starts', {time: timeString}); default: return t('calendar', '{type} {time} after the event starts', {type: alarm.action.value, time: timeString}); } } else { return t('calendar', '{type} {time} after the event ends', {type: getActionName(alarm), time: timeString}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm {time} after the event ends', {time: timeString}); case 'DISPLAY': return t('calendar', 'Pop-up {time} after the event ends', {time: timeString}); case 'EMAIL': return t('calendar', 'Email {time} after the event ends', {time: timeString}); case 'NONE': return t('calendar', 'None {time} after the event ends', {time: timeString}); default: return t('calendar', '{type} {time} after the event ends', {type: alarm.action.value, time: timeString}); } } } else { if (relatedToStart) { return t('calendar', '{type} at the event\'s start', {type: getActionName(alarm)}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm at the event\'s start'); case 'DISPLAY': return t('calendar', 'Pop-up at the event\'s start'); case 'EMAIL': return t('calendar', 'Email at the event\'s start'); case 'NONE': return t('calendar', 'None at the event\'s start'); default: return t('calendar', '{type} at the event\'s start', {type: alarm.action.value}); } } else { return t('calendar', '{type} at the event\'s end', {type: getActionName(alarm)}); switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm at the event\'s end'); case 'DISPLAY': return t('calendar', 'Pop-up at the event\'s end'); case 'EMAIL': return t('calendar', 'Email at the event\'s end'); case 'NONE': return t('calendar', 'None at the event\'s end'); default: return t('calendar', '{type} at the event\'s end', {type: alarm.action.value}); } } } } else { if (alarm.editor && moment.isMoment(alarm.editor.absMoment)) { switch(alarm.action.value) { case 'AUDIO': return t('calendar', 'Audio alarm at {time}', {time: alarm.editor.absMoment.format('LLLL')}); case 'DISPLAY': return t('calendar', 'Pop-up at {time}', {time: alarm.editor.absMoment.format('LLLL')}); case 'EMAIL': return t('calendar', 'Email at {time}', {time: alarm.editor.absMoment.format('LLLL')}); case 'NONE': return t('calendar', 'None at {time}', {time: alarm.editor.absMoment.format('LLLL')}); default: return t('calendar', '{type} at {time}', { type: getActionName(alarm), type: alarm.action.value, time: alarm.editor.absMoment.format('LLLL') }); } } else { return ''; } Loading
tests/js/unit/filters/reminderFilterSpec.js +22 −22 Original line number Diff line number Diff line Loading @@ -33,8 +33,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} before the event starts', { time: '15 minutes' }); }); it('should display email alarms correctly', function() { Loading @@ -52,8 +52,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Email', time: '15 minutes' }); })).toEqual('Email {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Email {time} before the event starts', { time: '15 minutes' }); }); it('should display popup alarms correctly', function() { Loading @@ -71,8 +71,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Pop-up', time: '15 minutes' }); })).toEqual('Pop-up {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Pop-up {time} before the event starts', { time: '15 minutes' }); }); it('should display none alarms correctly', function() { Loading @@ -90,8 +90,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'None', time: '15 minutes' }); })).toEqual('None {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'None {time} before the event starts', { time: '15 minutes' }); }); it('should display unknown alarms with it\'s identifier', function() { Loading Loading @@ -128,8 +128,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event starts', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} before the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} before the event starts', { time: '15 minutes' }); }); it('should display alarms correctly (relative before end)', function() { Loading @@ -147,8 +147,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: -900 } })).toEqual('{type} {time} before the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} before the event ends', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} before the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} before the event ends', { time: '15 minutes' }); }); it('should display alarms correctly (relative at start)', function() { Loading @@ -166,8 +166,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 0 } })).toEqual('{type} at the event\'s start'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} at the event\'s start', { type: 'Audio alarm'}); })).toEqual('Audio alarm at the event\'s start'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm at the event\'s start'); }); it('should display alarms correctly (relative at end)', function() { Loading @@ -185,8 +185,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 0 } })).toEqual('{type} at the event\'s end'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} at the event\'s end', { type: 'Audio alarm'}); })).toEqual('Audio alarm at the event\'s end'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm at the event\'s end'); }); it('should display alarms correctly (relative after start)', function() { Loading @@ -204,8 +204,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 900 } })).toEqual('{type} {time} after the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} after the event starts', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} after the event starts'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} after the event starts', { time: '15 minutes' }); }); it('should display alarms correctly (relative after end)', function() { Loading @@ -223,8 +223,8 @@ describe('The simpleReminderDescription filter', function () { type: 'duration', value: 900 } })).toEqual('{type} {time} after the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} {time} after the event ends', { type: 'Audio alarm', time: '15 minutes' }); })).toEqual('Audio alarm {time} after the event ends'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm {time} after the event ends', { time: '15 minutes' }); }); it('should display alarms correctly (absolute)', function() { Loading @@ -244,8 +244,8 @@ describe('The simpleReminderDescription filter', function () { type: 'date-time', value: moment('2013-02-08 09:30') } })).toEqual('{type} at {time}'); expect(t).toHaveBeenCalledWith( 'calendar', '{type} at {time}', { type: 'Audio alarm', time: 'Friday, February 8, 2013 9:30 AM' }); })).toEqual('Audio alarm at {time}'); expect(t).toHaveBeenCalledWith( 'calendar', 'Audio alarm at {time}', { time: 'Friday, February 8, 2013 9:30 AM' }); }); it('should return empty string when editor is not set for absolute alarms', function() { Loading