From 08e9f681979350d12719b1ab565b91ebc3349517 Mon Sep 17 00:00:00 2001 From: jelhan Date: Wed, 18 May 2016 13:18:36 -0700 Subject: [PATCH] remove polls isDateTime attribute --- api/classes/poll.php | 15 ++++---- api/tests/api/CreatePollCept.php | 4 +-- api/tests/api/GetLegacyPollWithUsersCept.php | 1 + api/tests/api/GetPollCept.php | 2 +- api/tests/api/GetPollWithUsersCept.php | 2 +- app/controllers/create/options-datetime.js | 1 - app/controllers/poll.js | 21 ++++++++--- app/controllers/poll/evaluation.js | 1 + app/controllers/poll/participation.js | 1 - app/models/poll.js | 3 -- app/routes/create.js | 1 - app/styles/app.less | 2 +- app/styles/bootstrap-switch.less | 4 --- .../components/create-options-datetime.hbs | 35 +++++++------------ app/templates/components/create-options.hbs | 1 - app/templates/create/options-datetime.hbs | 1 - app/templates/create/options.hbs | 1 - app/templates/poll/evaluation.hbs | 2 +- app/views/poll.js | 4 +-- package.json | 1 - .../create-options-datetime-test.js | 17 --------- 21 files changed, 45 insertions(+), 75 deletions(-) delete mode 100644 app/styles/bootstrap-switch.less diff --git a/api/classes/poll.php b/api/classes/poll.php index f08c1f2..c2c93c1 100644 --- a/api/classes/poll.php +++ b/api/classes/poll.php @@ -12,7 +12,6 @@ class Poll extends model { 'description', 'expirationDate', 'forceAnswer', - 'isDateTime', 'options', 'pollType', 'timezone', @@ -35,12 +34,12 @@ class Poll extends model { $this->getDir() ); } - + private function deleteDirRecursively($dir) { if (substr($dir, -1) !== '/') { throw new Exception('dir has to end on /'); } - + $dirHandle = opendir($dir); while (false !== ($filename = readdir($dirHandle))) { if ($filename === '.' || $filename === '..') { @@ -58,7 +57,7 @@ class Poll extends model { } } closedir($dirHandle); - + rmdir($dir); } @@ -70,7 +69,7 @@ class Poll extends model { } return $randomString; } - + protected function getDir() { if (($this->get('id') === null)) { throw new Exception('id must be set before calling getDir'); @@ -81,7 +80,7 @@ class Poll extends model { protected function getPollDir() { return $this->getDir(); } - + protected function getPath() { return $this->getDir() . 'poll_data'; } @@ -101,7 +100,7 @@ class Poll extends model { } closedir($dir); } - + return $users; } @@ -133,7 +132,7 @@ class Poll extends model { if (isset($data->poll) && is_object($data->poll)) { $data = $data->poll; } - + foreach($data as $key => $value) { if (strpos($key, 'encrypted') === 0) { $newKey = lcfirst(substr($key, 9)); diff --git a/api/tests/api/CreatePollCept.php b/api/tests/api/CreatePollCept.php index 02c4bf8..6feb7f6 100644 --- a/api/tests/api/CreatePollCept.php +++ b/api/tests/api/CreatePollCept.php @@ -1,6 +1,6 @@ wantTo('create a poll'); @@ -12,7 +12,7 @@ $pollId = $I->grabDataFromResponseByJsonPath('poll.id')[0]; \PHPUnit_Framework_Assert::assertNotRegExp( '/[^A-Za-z0-9]/', $pollId, - 'poll id only consists of numbers and letters' + 'poll id only consists of numbers and letters' ); \PHPUnit_Framework_Assert::assertTrue( strlen($pollId) === 10, diff --git a/api/tests/api/GetLegacyPollWithUsersCept.php b/api/tests/api/GetLegacyPollWithUsersCept.php index 66cf247..41043d3 100644 --- a/api/tests/api/GetLegacyPollWithUsersCept.php +++ b/api/tests/api/GetLegacyPollWithUsersCept.php @@ -21,6 +21,7 @@ $I->seeResponseIsJson(); $pollData = json_decode($pollJson, true)["poll"]; unset($pollData["serverExpirationDate"]); +unset($pollData["encryptedIsDateTime"]); foreach($pollData as $key => $value) { if (strpos($key, 'encrypted') === 0) { $key = lcfirst(substr($key, 9)); diff --git a/api/tests/api/GetPollCept.php b/api/tests/api/GetPollCept.php index 488ef8b..f960f24 100644 --- a/api/tests/api/GetPollCept.php +++ b/api/tests/api/GetPollCept.php @@ -1,7 +1,7 @@ { const date = moment(option.get('title')); const hasTime = moment(option.get('title'), 'YYYY-MM-DD', true).isValid() === false; - if (timezone) { + if (timezone && hasTime) { date.tz(timezone); } return dateObject.create({ @@ -117,6 +118,16 @@ export default Ember.Controller.extend({ return dates; }), + hasTimes: function() { + if (this.get('model.isMakeAPoll')) { + return false; + } else { + return this.get('model.options').map((option) => { + return moment(option.get('title'), 'YYYY-MM-DD', true).isValid() === false; + }); + } + }.property('model.options.[]'), + pollUrl: function() { return window.location.href; }.property('currentPath', 'encryptionKey'), diff --git a/app/controllers/poll/evaluation.js b/app/controllers/poll/evaluation.js index ca74f02..150d1ff 100644 --- a/app/controllers/poll/evaluation.js +++ b/app/controllers/poll/evaluation.js @@ -3,6 +3,7 @@ import Ember from 'ember'; export default Ember.Controller.extend({ dateGroups: Ember.computed.reads('pollController.dateGroups'), dates: Ember.computed.reads('pollController.dates'), + hasTimes: Ember.computed.reads('pollController.hasTimes'), pollController: Ember.inject.controller('poll'), sortedUsers: Ember.computed.sort('pollController.model.users', 'usersSorting'), usersSorting: ['creationDate'], diff --git a/app/controllers/poll/participation.js b/app/controllers/poll/participation.js index c752df2..47612f4 100644 --- a/app/controllers/poll/participation.js +++ b/app/controllers/poll/participation.js @@ -111,7 +111,6 @@ export default Ember.Controller.extend(Validations, { encryption: Ember.inject.service(), forceAnswer: Ember.computed.readOnly('pollController.model.forceAnswer'), i18n: Ember.inject.service(), - isDateTime: Ember.computed.readOnly('pollController.model.isDateTime'), isFreeText: Ember.computed.readOnly('pollController.model.isFreeText'), isFindADate: Ember.computed.readOnly('pollController.model.isFindADate'), diff --git a/app/models/poll.js b/app/models/poll.js index 9983111..87027f0 100644 --- a/app/models/poll.js +++ b/app/models/poll.js @@ -35,9 +35,6 @@ export default DS.Model.extend({ // Must all options been answered? forceAnswer: DS.attr('boolean'), - // If poll type is FindADate: are options only dates or dates + times? - isDateTime: DS.attr('boolean'), - // array of polls options options: MF.fragmentArray('option'), diff --git a/app/routes/create.js b/app/routes/create.js index fd933ab..ae4ee97 100644 --- a/app/routes/create.js +++ b/app/routes/create.js @@ -27,7 +27,6 @@ export default Ember.Route.extend({ creationDate: new Date(), forceAnswer: true, anonymousUser: false, - isDateTime: true, pollType: 'FindADate', timezone: null, expirationDate: moment().add(3, 'month').toISOString(), diff --git a/app/styles/app.less b/app/styles/app.less index dce2ddd..207be2e 100644 --- a/app/styles/app.less +++ b/app/styles/app.less @@ -1,6 +1,6 @@ @import "bower_components/bootstrap/less/bootstrap.less"; @import "bower_components/bootstrap-datepicker/less/datepicker3.less"; -@import "bootstrap-switch.less"; + table tr td .form-group { margin-bottom:0; } diff --git a/app/styles/bootstrap-switch.less b/app/styles/bootstrap-switch.less deleted file mode 100644 index 900814f..0000000 --- a/app/styles/bootstrap-switch.less +++ /dev/null @@ -1,4 +0,0 @@ -// prevent line breaks in label -.bootstrap-switch-label { - white-space: nowrap; -} diff --git a/app/templates/components/create-options-datetime.hbs b/app/templates/components/create-options-datetime.hbs index d509671..fb6478c 100644 --- a/app/templates/components/create-options-datetime.hbs +++ b/app/templates/components/create-options-datetime.hbs @@ -2,33 +2,22 @@ {{#fm-form action='submit' }} + {{#each groupedDatetimes as |groupedDatetime|}} + {{fm-input-group + type='time' + step=900 + label=groupedDatetime.value + content=groupedDatetime.items + addElement='addOption' + deleteElement='delOption' + }} + {{/each}} +
- {{bootstrap-switch - checked=isDateTime - labelText=(t 'create.options.defineTimes.label') - }} +
- - {{#if isDateTime}} - {{#each groupedDatetimes as |groupedDatetime|}} - {{fm-input-group - type='time' - step=900 - label=groupedDatetime.value - content=groupedDatetime.items - addElement='addOption' - deleteElement='delOption' - }} - {{/each}} - -
-
- -
-
- {{/if}} {{#fm-submit inputWrapperClass='col-sm-10 col-sm-offset-2' }} diff --git a/app/templates/components/create-options.hbs b/app/templates/components/create-options.hbs index 9b6dd55..b58501f 100644 --- a/app/templates/components/create-options.hbs +++ b/app/templates/components/create-options.hbs @@ -11,7 +11,6 @@ }} {{else}} {{create-options-dates - isDateTime=isDateTime options=options submit='submit' }} diff --git a/app/templates/create/options-datetime.hbs b/app/templates/create/options-datetime.hbs index 0b9685d..5ce49df 100644 --- a/app/templates/create/options-datetime.hbs +++ b/app/templates/create/options-datetime.hbs @@ -1,5 +1,4 @@ {{create-options-datetime - isDateTime=isDateTime options=options nextPage='nextPage' }} diff --git a/app/templates/create/options.hbs b/app/templates/create/options.hbs index ef9a2e3..16e5a81 100644 --- a/app/templates/create/options.hbs +++ b/app/templates/create/options.hbs @@ -1,5 +1,4 @@ {{create-options - isDateTime=model.isDateTime isFindADate=model.isFindADate isMakeAPoll=model.isMakeAPoll options=model.options diff --git a/app/templates/poll/evaluation.hbs b/app/templates/poll/evaluation.hbs index 38712c8..e9df16a 100644 --- a/app/templates/poll/evaluation.hbs +++ b/app/templates/poll/evaluation.hbs @@ -15,7 +15,7 @@
- {{#if model.isDateTime}} + {{#if hasTimes}} {{#each dateGroups as |dateGroup|}} diff --git a/app/views/poll.js b/app/views/poll.js index 0f1e2de..6e46c8b 100644 --- a/app/views/poll.js +++ b/app/views/poll.js @@ -14,9 +14,9 @@ export default Ember.View.extend({ /* * show timezone modal if * - local timezone differs to timezone poll got created with and - * - poll is datetime + * - poll has times */ - if (this.get('controller.timezoneDiffers') && this.get('controller.model.isDateTime')) { + if (this.get('controller.timezoneDiffers') && this.get('controller.hasTimes')) { Ember.$('#timezoneDiffers').modal(); } } diff --git a/package.json b/package.json index 64ae910..1b0d638 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "broccoli-unwatched-tree": "^0.1.1", "connect-restreamer": "^1.0.1", "cors": "^2.5.3", - "ember-bootstrap-switch": "1.13.1", "ember-cli": "1.13.13", "ember-cli-acceptance-test-helpers": "0.4.0", "ember-cli-app-version": "^1.0.0", diff --git a/tests/integration/components/create-options-datetime-test.js b/tests/integration/components/create-options-datetime-test.js index d4bec84..baf4b53 100644 --- a/tests/integration/components/create-options-datetime-test.js +++ b/tests/integration/components/create-options-datetime-test.js @@ -14,23 +14,6 @@ moduleForComponent('create-options-datetime', 'Integration | Component | create * that ones could be identifed by class 'ws-inputreplace' */ -test('time input is toggled by radio switch', function(assert) { - this.set('options', [ - Ember.Object.create({ title: '2015-01-01' }) - ]); - this.set('isDateTime', false); - this.render(hbs`{{create-options-datetime options=options isDateTime=isDateTime}}`); - assert.ok(this.$('.grouped-input input').length === 0); - Ember.run(() => { - this.$('.bootstrap-switch-handle-off').click(); - }); - assert.ok(this.$('.grouped-input input').length > 0); - Ember.run(() => { - this.$('.bootstrap-switch-handle-on').click(); - }); - assert.ok(this.$('.grouped-input input').length === 0); -}); - test('it generates inpute field for options iso 8601 date string (without time)', function(assert) { this.set('options', [ Ember.Object.create({ title: '2015-01-01' })