Skip to content

Commit f2d6609

Browse files
codepool867hb
andauthored
feat: Make rooms sortable (#5743)
Co-authored-by: hb <[email protected]>
1 parent 4006f52 commit f2d6609

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

app/components/forms/wizard/sessions-speakers-step.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,13 @@ export default Component.extend(EventWizardMixin, FormMixin, {
139139
return grouped;
140140
}),
141141

142-
microlocations: computed('[email protected]', function() {
143-
return this.data.event.microlocations.filterBy('isDeleted', false);
142+
microlocations: computed('[email protected]', '[email protected]', function() {
143+
const sortedRooms = this.data.event.microlocations.sortBy('position').filterBy('isDeleted', false);
144+
sortedRooms.forEach((room, idx) => {
145+
room.set('position', idx);
146+
});
147+
148+
return sortedRooms;
144149
}),
145150

146151
complexCustomForms: computed('[email protected]', function() {
@@ -183,9 +188,6 @@ export default Component.extend(EventWizardMixin, FormMixin, {
183188
case 'track':
184189
this.data.tracks.addObject(this.store.createRecord('track'));
185190
break;
186-
case 'microlocation':
187-
this.data.microlocations.addObject(this.store.createRecord('microlocation'));
188-
break;
189191
}
190192
},
191193
addCustomField() {
@@ -197,6 +199,27 @@ export default Component.extend(EventWizardMixin, FormMixin, {
197199
removeField(field) {
198200
this.data.customForms.removeObject(field);
199201
},
202+
addRoom(index) {
203+
this.microlocations.forEach(room => {
204+
const pos = room.get('position');
205+
pos > index && room.set('position', pos + 1);
206+
});
207+
this.data.event.microlocations.addObject(this.store.createRecord('microlocation', { position: index + 1 }));
208+
},
209+
removeRoom(room, index) {
210+
room.deleteRecord();
211+
this.microlocations.forEach(item => {
212+
const pos = item.get('position');
213+
pos > index && item.set('position', pos - 1);
214+
});
215+
},
216+
moveRoom(item, direction) {
217+
const idx = item.get('position');
218+
const otherIdx = direction === 'up' ? (idx - 1) : (idx + 1);
219+
const other = this.microlocations.find(item => item.get('position') === otherIdx);
220+
other.set('position', idx);
221+
item.set('position', otherIdx);
222+
},
200223
resetCFS() {
201224
this.set('data.speakersCall.announcement', null);
202225
},

app/controllers/events/view/scheduler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export default class extends Controller {
1818
return false;
1919
}
2020

21+
@computed('model.microlocations')
22+
get microlocations() {
23+
return this.model.microlocations.sortBy('position');
24+
}
25+
2126
@computed('model.unscheduled', 'filter')
2227
get unscheduledSessions() {
2328
if (!this.filter || !this.model.unscheduled) {return this.model.unscheduled}

app/models/microlocation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class Microlocation extends ModelBase.extend({
77
floor : attr('number'),
88
latitude : attr('number'),
99
longitude : attr('number'),
10+
position : attr('number', { defaultValue: 0 }),
1011

1112
sessions : hasMany('session'),
1213
event : belongsTo('event'),

app/templates/components/forms/wizard/sessions-speakers-step.hbs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
<div class="field">
6060
<label class="required">{{t 'Microlocations or Virtual Online Rooms'}}</label>
61-
{{#each this.microlocations as |microlocation|}}
61+
{{#each this.microlocations as |microlocation index|}}
6262
<div class="{{if this.device.isMobile 'grouped'}} fields">
6363
<div class="{{unless this.device.isMobile 'three wide'}} field">
6464
<Input @type="text" @value={{microlocation.name}} placeholder="Name" />
@@ -67,15 +67,27 @@
6767
<div class="ui action input fluid">
6868
<Input @type="number" @value={{microlocation.floor}} placeholder="Floor" />
6969
{{#if (gt this.microlocations.length 1)}}
70-
<button class="ui icon red button" type="button" {{action 'removeItem' microlocation}}>
70+
<button class="ui icon red button" type="button" {{action 'removeRoom' microlocation index}}>
7171
<i class="minus icon"></i>
7272
</button>
7373
{{/if}}
74-
<button class="ui icon primary button" type="button" {{action 'addItem' 'microlocation'}}>
74+
<button class="ui icon primary button" type="button" {{action 'addRoom' index}}>
7575
<i class="plus icon"></i>
7676
</button>
7777
</div>
7878
</div>
79+
<div class="ui icon buttons {{if this.device.isLargeMonitor 'right floated'}}">
80+
{{#if (not-eq index 0)}}
81+
<button type="button" class="ui button" {{action "moveRoom" microlocation "up"}} data-content="Move room up">
82+
<i class="up arrow icon"></i>
83+
</button>
84+
{{/if}}
85+
{{#if (not-eq microlocation.position (dec this.microlocations.length))}}
86+
<button type="button" class="ui button" {{action "moveRoom" microlocation "down"}} data-content="Move room down">
87+
<i class="down arrow icon"></i>
88+
</button>
89+
{{/if}}
90+
</div>
7991
</div>
8092
{{/each}}
8193
</div>

app/templates/events/view/scheduler.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Schedule
2727
@event={{this.model.event}}
2828
@sessions={{this.model.scheduled}}
29-
@rooms={{this.model.microlocations}}
29+
@rooms={{this.microlocations}}
3030
@editable={{true}}
3131
@droppable={{true}}
3232
@defaultTimedEventDuration={{this.model.defaultDuration}}

0 commit comments

Comments
 (0)