From c5c11e30e5cffc18f7cc21221eb268ec8fa2a200 Mon Sep 17 00:00:00 2001 From: lodewiges Date: Sun, 27 Oct 2024 01:57:37 +0200 Subject: [PATCH 1/8] first commit --- app/abilities/study-room-presence copy.js | 15 ++ app/components/index/authenticated.hbs | 1 + app/components/tools/board-room-presence.hbs | 2 +- app/components/tools/study-room-presence.hbs | 135 ++++++++++++++++++ app/components/tools/study-room-presence.js | 122 ++++++++++++++++ app/models/study-room-presence.js | 11 ++ app/styles/app.scss | 2 +- ...-room-presence.scss => room-presence.scss} | 2 +- mirage/config.js | 1 + mirage/scenarios/default.js | 1 + 10 files changed, 289 insertions(+), 3 deletions(-) create mode 100644 app/abilities/study-room-presence copy.js create mode 100644 app/components/tools/study-room-presence.hbs create mode 100644 app/components/tools/study-room-presence.js create mode 100644 app/models/study-room-presence.js rename app/styles/components/tools/{board-room-presence.scss => room-presence.scss} (94%) diff --git a/app/abilities/study-room-presence copy.js b/app/abilities/study-room-presence copy.js new file mode 100644 index 000000000..2ff1bc004 --- /dev/null +++ b/app/abilities/study-room-presence copy.js @@ -0,0 +1,15 @@ +import { Ability } from 'ember-can'; + +export default class StudyRoomPresence extends Ability { + get canShow() { + return this.session.hasPermission('study-room-presence.read'); + } + + get canCreate() { + return this.session.hasPermission('study-room-presence.create'); + } + + get canDestroy() { + return this.session.hasPermission('study-room-presence.destroy'); + } +} diff --git a/app/components/index/authenticated.hbs b/app/components/index/authenticated.hbs index 4a82afe64..b3db07a79 100644 --- a/app/components/index/authenticated.hbs +++ b/app/components/index/authenticated.hbs @@ -1,6 +1,7 @@ + diff --git a/app/components/tools/board-room-presence.hbs b/app/components/tools/board-room-presence.hbs index b70989892..5ac073729 100644 --- a/app/components/tools/board-room-presence.hbs +++ b/app/components/tools/board-room-presence.hbs @@ -1,4 +1,4 @@ -
+
Bestuurskamer diff --git a/app/components/tools/study-room-presence.hbs b/app/components/tools/study-room-presence.hbs new file mode 100644 index 000000000..dcb1ae323 --- /dev/null +++ b/app/components/tools/study-room-presence.hbs @@ -0,0 +1,135 @@ +
+ + + 2de kamer + + + + {{#each sortedPresences as |presence|}} +
+
+ + {{presence.user.fullNameWithNickname}} + +
+ + {{t (concat 'component.tools.studyRoomPresence.' presence.status)}} + van + {{moment-format presence.startTime 'HH:mm'}} + tot + {{moment-format presence.endTime 'HH:mm'}} + +
+ {{else}} +
Er is niemand aanwezig
+ {{/each}} + + {{#if (can 'create study-room-presences')}} + + + + {{/if}} +
+
+
+ +{{#if presenceModalIsOpen}} + + + {{#if sortedPresences}} + + + + + + + + + + + {{#each sortedPresences as |presence|}} + + + + + + + {{/each}} + +
PersoonStatusTot
{{presence.user.fullNameWithNickname}} + {{t + (concat 'component.tools.studyRoomPresence.' presence.status) + }} + {{moment-format presence.endTime 'HH:mm'}} + {{#if (can 'destroy study-room-presences')}} + + {{/if}} +
+ {{else}} +
Er zijn geen alphanen aanwezig
+ {{/if}} + + {{#if currentUserPresence}} + + + + + + + {{else}} + + {{/if}} +
+
+{{/if}} \ No newline at end of file diff --git a/app/components/tools/study-room-presence.js b/app/components/tools/study-room-presence.js new file mode 100644 index 000000000..a9276969e --- /dev/null +++ b/app/components/tools/study-room-presence.js @@ -0,0 +1,122 @@ +import { task, timeout } from 'ember-concurrency'; +import Component from '@ember/component'; +import Ember from 'ember'; +import { computed } from '@ember/object'; +import { equal } from '@ember/object/computed'; +import moment from 'moment'; +import { inject as service } from '@ember/service'; + +const StudyRoomPresence = Component.extend({ + session: service(), + store: service(), + abilities: service(), + presenceModalIsOpen: false, + model: [], + + statusOptions: [ + { + value: 'present', + label: 'Aanwezig', + }, + { + value: 'busy', + label: 'Bezig', + }, + { + value: 'absent', + label: 'Afwezig', + }, + ], + + // Periodically poll for new studyroom data + poll: task(function* () { + while (!Ember.testing) { + this.fetchData.perform(); + yield timeout(1000 * 30); // Wait 30 seconds + } + }) + .drop() + .on('didInsertElement'), + + // Fetch task is separate from polling task, so we can call it individually. + fetchData: task(function* () { + /* eslint-disable camelcase */ + const model = yield this.store.query('study-room-presence', { + filter: { current_and_future: true }, + }); + /* eslint-enable camelcase */ + + this.set('model', model); + }).restartable(), + + currentUserPresence: computed('model.[]', function () { + return ( + this.model.filter((presence) => presence.get('user.isCurrentUser'))[0] || + null + ); + }), + + sortedPresences: computed('model.[]', function () { + return this.model.sortBy('endTime'); + }), + + overallStatus: computed('model.[]', function () { + const currentStatusses = this.model + .filter((presence) => { + return moment().isBetween( + moment(presence.get('startTime')), + moment(presence.get('endTime')), + 'minute', + '[)' + ); + }) + .mapBy('status'); + + if (currentStatusses.includes('present')) { + return 'present'; + } else if (currentStatusses.includes('busy')) { + return 'busy'; + } + + return 'absent'; + }), + + saveButtonDisabled: equal('currentUserPresence', null), + + actions: { + setPresenceModalState(state) { + this.set('presenceModalIsOpen', state === 'open'); + }, + + deletePresence() { + this.currentUserPresence.destroyRecord().then(() => { + this.set('currentUserPresence', null); + }); + }, + + newPresence() { + if (this.abilities.can('create study-room-presences')) { + const newPresenceObject = this.store.createRecord( + 'study-room-presence', + { + startTime: moment().startOf('minute').toDate(), + endTime: moment().startOf('minute').add(1, 'hours').toDate(), + status: 'present', + user: this.session.currentUser, + } + ); + this.set('currentUserPresence', newPresenceObject); + } + }, + + save() { + const presence = this.currentUserPresence; + const fetch = this.fetchData; + + presence.save().then(() => fetch.perform()); + this.set('presenceModalIsOpen', false); + }, + }, +}); + +export default studyRoomPresence; diff --git a/app/models/study-room-presence.js b/app/models/study-room-presence.js new file mode 100644 index 000000000..5721bbf03 --- /dev/null +++ b/app/models/study-room-presence.js @@ -0,0 +1,11 @@ +import Model, { belongsTo, attr } from '@ember-data/model'; + +export default class StudyRoomPresence extends Model { + // Properties + @attr startTime; + @attr endTime; + @attr status; + + // Relations + @belongsTo user; +} diff --git a/app/styles/app.scss b/app/styles/app.scss index d1288923e..45ed2c239 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -33,7 +33,7 @@ @import 'components/quickpost'; @import 'components/sidebar'; @import 'components/social-media-buttons'; -@import 'components/tools/board-room-presence'; +@import 'components/tools/room-presence'; @import 'components/tools/upcoming-birthdays'; @import 'components/tools/upcoming-activities'; @import 'components/tools/forum-tool'; diff --git a/app/styles/components/tools/board-room-presence.scss b/app/styles/components/tools/room-presence.scss similarity index 94% rename from app/styles/components/tools/board-room-presence.scss rename to app/styles/components/tools/room-presence.scss index 683763d55..57a337521 100644 --- a/app/styles/components/tools/board-room-presence.scss +++ b/app/styles/components/tools/room-presence.scss @@ -10,7 +10,7 @@ font-weight: bold; } -.board-room-presence-dropdown { +.room-presence-dropdown { color: $white; } diff --git a/mirage/config.js b/mirage/config.js index 8241fd8ae..1afd1afa4 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -32,6 +32,7 @@ export default function () { this.resource('groups'); this.resource('quickpost_messages'); this.resource('board_room_presences'); + this.resource('study_room_presences'); this.resource('photo_albums'); this.resource('photo_comments'); this.resource('photo_tags'); diff --git a/mirage/scenarios/default.js b/mirage/scenarios/default.js index db12aec4a..b1e3f3afa 100644 --- a/mirage/scenarios/default.js +++ b/mirage/scenarios/default.js @@ -8,6 +8,7 @@ export default function (server) { 'article', 'article_comment', 'board_room_presence', + 'study_room_presence', 'group', 'membership', 'photo_album', From cbf40b03b2052d1638ea2c6209bcae54f6954104 Mon Sep 17 00:00:00 2001 From: lodewiges Date: Sun, 27 Oct 2024 02:18:00 +0200 Subject: [PATCH 2/8] Fixed Lint --- app/components/tools/study-room-presence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/tools/study-room-presence.js b/app/components/tools/study-room-presence.js index a9276969e..fa31ee8fb 100644 --- a/app/components/tools/study-room-presence.js +++ b/app/components/tools/study-room-presence.js @@ -119,4 +119,4 @@ const StudyRoomPresence = Component.extend({ }, }); -export default studyRoomPresence; +export default StudyRoomPresence; From 1e529e9e6326e8da74dc2f199d93cc31ac005ad5 Mon Sep 17 00:00:00 2001 From: lodewiges Date: Sun, 27 Oct 2024 02:38:05 +0200 Subject: [PATCH 3/8] Fixed a mistake in the name of a file --- .../{study-room-presence copy.js => study-room-presence.js} | 0 app/components/tools/study-room-presence.hbs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename app/abilities/{study-room-presence copy.js => study-room-presence.js} (100%) diff --git a/app/abilities/study-room-presence copy.js b/app/abilities/study-room-presence.js similarity index 100% rename from app/abilities/study-room-presence copy.js rename to app/abilities/study-room-presence.js diff --git a/app/components/tools/study-room-presence.hbs b/app/components/tools/study-room-presence.hbs index dcb1ae323..d8b4fedc4 100644 --- a/app/components/tools/study-room-presence.hbs +++ b/app/components/tools/study-room-presence.hbs @@ -1,6 +1,6 @@
- + 2de kamer From 265bb3c186c3c88fde220f861e42313b952f80cd Mon Sep 17 00:00:00 2001 From: lodewiges Date: Sun, 27 Oct 2024 12:53:00 +0100 Subject: [PATCH 4/8] changed options and added translations --- app/components/index/authenticated.hbs | 2 +- app/components/tools/study-room-presence.js | 18 +++++++++--------- translations/en.yaml | 4 ++++ translations/nl.yaml | 4 ++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/components/index/authenticated.hbs b/app/components/index/authenticated.hbs index b3db07a79..e69b3c6d2 100644 --- a/app/components/index/authenticated.hbs +++ b/app/components/index/authenticated.hbs @@ -1,7 +1,7 @@ - + diff --git a/app/components/tools/study-room-presence.js b/app/components/tools/study-room-presence.js index fa31ee8fb..4287a71d5 100644 --- a/app/components/tools/study-room-presence.js +++ b/app/components/tools/study-room-presence.js @@ -15,16 +15,16 @@ const StudyRoomPresence = Component.extend({ statusOptions: [ { - value: 'present', - label: 'Aanwezig', + value: 'chilling', + label: 'Chillen', }, { - value: 'busy', - label: 'Bezig', + value: 'Studying', + label: 'Studeren', }, { - value: 'absent', - label: 'Afwezig', + value: 'banaan', + label: 'Banaan', }, ], @@ -74,11 +74,11 @@ const StudyRoomPresence = Component.extend({ if (currentStatusses.includes('present')) { return 'present'; - } else if (currentStatusses.includes('busy')) { - return 'busy'; + } else if (currentStatusses.includes('Studeren')) { + return 'Studying'; } - return 'absent'; + return 'banaan'; }), saveButtonDisabled: equal('currentUserPresence', null), diff --git a/translations/en.yaml b/translations/en.yaml index b11419698..f09759a8d 100644 --- a/translations/en.yaml +++ b/translations/en.yaml @@ -276,6 +276,10 @@ component: present: Present busy: Busy absent: Absent + studyRoomPresence: + chilling: Chilling + studying: Studying + banaan: Banaan userComment: anonymous: Anonymous user mixin: diff --git a/translations/nl.yaml b/translations/nl.yaml index d44a0eaee..95169c178 100644 --- a/translations/nl.yaml +++ b/translations/nl.yaml @@ -281,6 +281,10 @@ component: present: Aanwezig busy: Bezig absent: Afwezig + studyRoomPresence: + chilling: Chillen + studying: Studeren + banaan: Banaan userComment: anonymous: Anonieme gebruiker mixin: From 968e36edea14267e6e9e19882415d944adc0c64d Mon Sep 17 00:00:00 2001 From: lodewiges Date: Sun, 27 Oct 2024 14:24:18 +0100 Subject: [PATCH 5/8] Fixed errors --- app/components/tools/study-room-presence.js | 10 +++++----- app/styles/components/tools/room-presence.scss | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/components/tools/study-room-presence.js b/app/components/tools/study-room-presence.js index 4287a71d5..2da13313f 100644 --- a/app/components/tools/study-room-presence.js +++ b/app/components/tools/study-room-presence.js @@ -19,7 +19,7 @@ const StudyRoomPresence = Component.extend({ label: 'Chillen', }, { - value: 'Studying', + value: 'studying', label: 'Studeren', }, { @@ -72,9 +72,9 @@ const StudyRoomPresence = Component.extend({ }) .mapBy('status'); - if (currentStatusses.includes('present')) { - return 'present'; - } else if (currentStatusses.includes('Studeren')) { + if (currentStatusses.includes('chilling')) { + return 'Chillen'; + } else if (currentStatusses.includes('studeren')) { return 'Studying'; } @@ -101,7 +101,7 @@ const StudyRoomPresence = Component.extend({ { startTime: moment().startOf('minute').toDate(), endTime: moment().startOf('minute').add(1, 'hours').toDate(), - status: 'present', + status: 'Studying', user: this.session.currentUser, } ); diff --git a/app/styles/components/tools/room-presence.scss b/app/styles/components/tools/room-presence.scss index 57a337521..42416284f 100644 --- a/app/styles/components/tools/room-presence.scss +++ b/app/styles/components/tools/room-presence.scss @@ -26,6 +26,18 @@ background-color: $brand-danger; } +.label-chilling { + background-color: $brand-success; +} + +.label-studying { + background-color: $brand-warning; +} + +.label-banaan { + background-color: $brand-success; +} + .edit-presence { .edit-presence-row { margin: 5px; From 6ac20400e56b3723894e533c1869312af36e2f64 Mon Sep 17 00:00:00 2001 From: Jorai Geertsema Date: Sun, 15 Dec 2024 02:53:41 +0100 Subject: [PATCH 6/8] updated js file --- app/components/tools/study-room-presence.js | 141 ++++++++++---------- 1 file changed, 74 insertions(+), 67 deletions(-) diff --git a/app/components/tools/study-room-presence.js b/app/components/tools/study-room-presence.js index 2da13313f..c04d8d1a4 100644 --- a/app/components/tools/study-room-presence.js +++ b/app/components/tools/study-room-presence.js @@ -1,19 +1,22 @@ -import { task, timeout } from 'ember-concurrency'; -import Component from '@ember/component'; -import Ember from 'ember'; -import { computed } from '@ember/object'; -import { equal } from '@ember/object/computed'; +import { dropTask, restartableTask, timeout } from 'ember-concurrency'; +import Component from '@glimmer/component'; +// import Ember from 'ember'; +import { action } from '@ember/object'; import moment from 'moment'; import { inject as service } from '@ember/service'; +import { tracked } from '@glimmer/tracking'; +import Ember from 'ember'; -const StudyRoomPresence = Component.extend({ - session: service(), - store: service(), - abilities: service(), - presenceModalIsOpen: false, - model: [], +export default class BoardRoomPresence extends Component { + @service session; + @service store; + @service abilities; - statusOptions: [ + @tracked presenceModalIsOpen = false; + @tracked model = []; + @tracked newCurrentUserPresence = null; + + statusOptions = [ { value: 'chilling', label: 'Chillen', @@ -26,41 +29,47 @@ const StudyRoomPresence = Component.extend({ value: 'banaan', label: 'Banaan', }, - ], + ]; - // Periodically poll for new studyroom data - poll: task(function* () { + @dropTask({ cancelOn: 'didInsertElement' }) *poll() { while (!Ember.testing) { - this.fetchData.perform(); + yield this.fetchData.perform(); yield timeout(1000 * 30); // Wait 30 seconds } - }) - .drop() - .on('didInsertElement'), + } - // Fetch task is separate from polling task, so we can call it individually. - fetchData: task(function* () { + @restartableTask *fetchData() { /* eslint-disable camelcase */ - const model = yield this.store.query('study-room-presence', { + this.model = yield this.store.query('study-room-presence', { filter: { current_and_future: true }, }); /* eslint-enable camelcase */ + } - this.set('model', model); - }).restartable(), + constructor() { + super(...arguments); + this.poll.perform(); + } - currentUserPresence: computed('model.[]', function () { + get currentUserPresence() { + if (this.newCurrentUserPresence) { + return this.newCurrentUserPresence; + } return ( - this.model.filter((presence) => presence.get('user.isCurrentUser'))[0] || + this.model.filter((presence) => presence.user.get('isCurrentUser'))[0] || null ); - }), + } - sortedPresences: computed('model.[]', function () { + set currentUserPresence(presence) { + this.newCurrentUserPresence = presence; + } + + get sortedPresences() { return this.model.sortBy('endTime'); - }), + } - overallStatus: computed('model.[]', function () { + get overallStatus() { const currentStatusses = this.model .filter((presence) => { return moment().isBetween( @@ -74,49 +83,47 @@ const StudyRoomPresence = Component.extend({ if (currentStatusses.includes('chilling')) { return 'Chillen'; - } else if (currentStatusses.includes('studeren')) { + } + + if (currentStatusses.includes('studeren')) { return 'Studying'; } return 'banaan'; - }), + } - saveButtonDisabled: equal('currentUserPresence', null), + get saveButtonDisabled() { + return this.currentUserPresence === null; + } - actions: { - setPresenceModalState(state) { - this.set('presenceModalIsOpen', state === 'open'); - }, + @action + setPresenceModalState(state) { + this.presenceModalIsOpen = state === 'open'; + } - deletePresence() { - this.currentUserPresence.destroyRecord().then(() => { - this.set('currentUserPresence', null); - }); - }, - - newPresence() { - if (this.abilities.can('create study-room-presences')) { - const newPresenceObject = this.store.createRecord( - 'study-room-presence', - { - startTime: moment().startOf('minute').toDate(), - endTime: moment().startOf('minute').add(1, 'hours').toDate(), - status: 'Studying', - user: this.session.currentUser, - } - ); - this.set('currentUserPresence', newPresenceObject); - } - }, - - save() { - const presence = this.currentUserPresence; - const fetch = this.fetchData; + @action + deletePresence() { + this.currentUserPresence.destroyRecord().then(() => { + this.currentUserPresence = null; + }); + } + + @action + newPresence() { + this.currentUserPresence = this.store.createRecord('board-room-presence', { + startTime: moment().startOf('minute').toDate(), + endTime: moment().startOf('minute').add(1, 'hours').toDate(), + status: 'present', + user: this.session.currentUser, + }); + } - presence.save().then(() => fetch.perform()); - this.set('presenceModalIsOpen', false); - }, - }, -}); + @action + save() { + const presence = this.currentUserPresence; + const fetch = this.fetchData; + presence.save().then(() => fetch.perform()); + this.presenceModalIsOpen = false; + } +} -export default StudyRoomPresence; From 4e3722b6b9eedf39527ba6158db8b09f96616e30 Mon Sep 17 00:00:00 2001 From: Jorai Geertsema Date: Sun, 15 Dec 2024 02:57:46 +0100 Subject: [PATCH 7/8] update handbrake file --- app/components/tools/study-room-presence.hbs | 92 ++++++++++---------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/app/components/tools/study-room-presence.hbs b/app/components/tools/study-room-presence.hbs index d8b4fedc4..f5d382a31 100644 --- a/app/components/tools/study-room-presence.hbs +++ b/app/components/tools/study-room-presence.hbs @@ -2,7 +2,7 @@ 2de kamer - + - {{#each sortedPresences as |presence|}} + {{#each this.sortedPresences as |presence|}}
@@ -28,12 +28,12 @@ {{else}}
Er is niemand aanwezig
{{/each}} - + {{#if (can 'create study-room-presences')}}