Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f5c6d6d
Change omnichannel office hours data structure
Jun 4, 2020
387e801
Rename omnichannel office hours templates
Jun 4, 2020
6d4b2e6
Renaming things from office hour to business hour
Jun 5, 2020
a1adbbd
Partially remove LivechatOfficeHour model
Jun 5, 2020
4803883
remove obsolete setting
Jun 5, 2020
ebd93a9
Remove settings from the template
Jun 5, 2020
5a911b3
Add support to cron jobs on omnichannel business hours
Jun 9, 2020
acf7b70
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 9, 2020
4f93201
Add dynamic template to omnichannel business hours
Jun 9, 2020
7d3e345
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 9, 2020
d94d750
Open and close business hours
Jun 12, 2020
d3e2670
Remove references to LivechatOfficeHours
Jun 12, 2020
bb4c82b
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 12, 2020
25c4d88
Open and close business hour automatically on startup and setting cha…
Jun 15, 2020
1becb7c
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 15, 2020
a2b2c9b
Improve open and close business hours process
Jun 16, 2020
c496ca2
Removing separated interfaces
Jun 16, 2020
388afa0
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 16, 2020
e0a0021
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 17, 2020
0b05ad8
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 17, 2020
9371c3d
Apply suggestions from review
Jun 17, 2020
83e32f5
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 17, 2020
7765960
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 19, 2020
36f3673
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 19, 2020
7e48e71
Changing pt-br term
Jun 19, 2020
c22bd6d
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 19, 2020
96bf764
General improvements on business hour layout
Jun 19, 2020
572ecea
Merge remote-tracking branch 'origin/improvements/refactor-livechat-o…
Jun 19, 2020
4e74a73
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 19, 2020
243cf63
Apply suggestions from review
Jun 19, 2020
5554c67
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 20, 2020
4e6bd27
Remove online verification
Jun 20, 2020
e788448
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 20, 2020
ef33a6a
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 20, 2020
b724b3f
Change data structure
Jun 21, 2020
ad3f2d7
Ignore if collection does not exist
Jun 21, 2020
704c2e1
Merge branch 'develop' into improvements/refactor-livechat-office-hours
Jun 21, 2020
25218ee
Merge remote-tracking branch 'origin/improvements/refactor-livechat-o…
Jun 21, 2020
b5f3cc8
Merge branch 'develop' into improvements/refactor-livechat-office-hours
renatobecker Jun 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/authorization/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Meteor.startup(function() {
{ _id: 'view-livechat-appearance', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-webhooks', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-facebook', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-officeHours', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-business-hours', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-room-closed-same-department', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-room-closed-by-another-agent', roles: ['livechat-manager', 'admin'] },
{ _id: 'view-livechat-room-customfields', roles: ['livechat-manager', 'livechat-agent', 'admin'] },
Expand Down
3 changes: 0 additions & 3 deletions app/livechat/client/collections/livechatOfficeHour.js

This file was deleted.

8 changes: 4 additions & 4 deletions app/livechat/client/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ AccountBox.addRoute({
}, livechatManagerRoutes, load);

AccountBox.addRoute({
name: 'livechat-officeHours',
path: '/officeHours',
name: 'livechat-business-hours',
path: '/businessHours',
sideNav: 'livechatFlex',
i18nPageTitle: 'Office_Hours',
pageTemplate: 'livechatOfficeHours',
i18nPageTitle: 'Business_Hours',
pageTemplate: 'livechatMainBusinessHours',
}, livechatManagerRoutes, load);

AccountBox.addRoute({
Expand Down
3 changes: 2 additions & 1 deletion app/livechat/client/views/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import './app/livechatCustomFieldForm';
import './app/livechatDepartmentForm';
import './app/livechatDepartments';
import './app/livechatInstallation';
import './app/livechatOfficeHours';
import './app/livechatTriggers';
import './app/livechatTriggersForm';
import './app/livechatManagers';
import './app/integrations/livechatIntegrationWebhook';
import './app/integrations/livechatIntegrationFacebook';
import './app/triggers/livechatTriggerAction';
import './app/triggers/livechatTriggerCondition';
import './app/business-hours/livechatBusinessHoursForm';
import './app/business-hours/livechatMainBusinessHours';
28 changes: 28 additions & 0 deletions app/livechat/client/views/app/business-hours/BusinessHours.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Meteor } from 'meteor/meteor';

import { IBusinessHour } from './IBusinessHour';
import { SingleBusinessHour } from './Single';
import { callbacks } from '../../../../../callbacks/client';

class BusinessHoursManager {
private businessHour: IBusinessHour;

onStartBusinessHourManager(businessHour: IBusinessHour): void {
this.registerBusinessHour(businessHour);
}

registerBusinessHour(businessHour: IBusinessHour): void {
this.businessHour = businessHour;
}

getTemplate(): string {
return this.businessHour.getView();
}
}

export const businessHourManager = new BusinessHoursManager();

Meteor.startup(() => {
const { BusinessHourClass } = callbacks.run('on-business-hour-start', { BusinessHourClass: SingleBusinessHour });
businessHourManager.onStartBusinessHourManager(new BusinessHourClass() as IBusinessHour);
});
3 changes: 3 additions & 0 deletions app/livechat/client/views/app/business-hours/IBusinessHour.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IBusinessHour {
getView(): string;
}
7 changes: 7 additions & 0 deletions app/livechat/client/views/app/business-hours/Single.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IBusinessHour } from './IBusinessHour';

export class SingleBusinessHour implements IBusinessHour {
getView(): string {
return 'livechatBusinessHoursForm';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template name="livechatBusinessHoursForm">
{{#requiresPermission 'view-livechat-business-hours'}}
<form class="rocket-form" id="businessHoursForm">

<!-- days open -->
<fieldset>
<legend>{{_ "Open_days_of_the_week"}}</legend>
{{#each day in days}}
{{#if open day}}
<label class="dayOpenCheck"><input type="checkbox" name={{openName day}} checked>{{name day}}
</label>
{{else}}
<label class="dayOpenCheck"><input type="checkbox" name={{openName day}}>{{name day}}</label>
{{/if}}
{{/each}}
</fieldset>

<!-- times -->
<fieldset>
<legend>{{_ "Hours"}}</legend>
{{#each day in days}}
<div class="input-line">
<h1><strong>{{name day}}</strong></h1>
<table style="width:100%;">
<tr>
<td>{{_ "Open"}}:</td>
<td>{{_ "Close"}}:</td>
</tr>
<tr>
<td>
<div style="margin-right:30px">
<input type="time" class="preview-settings rc-input__element" name={{startName
day}} id={{startName day}} value={{start day}} style="width=100px;">
</div>
</td>
<td>
<div style="margin-right:30px">
<input type="time" class="preview-settings rc-input__element" name={{finishName
day}} id={{finishName day}} value={{finish day}} style="width=100px;">
</div>
</td>
</tr>
</table>
</div>
{{/each}}
</fieldset>


<div class="rc-button__group submit">
<button class="rc-button rc-button--primary"><i class="icon-floppy"></i>{{_ "Save"}}</button>
</div>
</form>
{{/requiresPermission}}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import toastr from 'toastr';
import moment from 'moment';

import { t, handleError, APIClient } from '../../../../../utils/client';
import './livechatBusinessHoursForm.html';

Template.livechatBusinessHoursForm.helpers({
days() {
return Template.instance().businessHour.get().workHours;
},
startName(day) {
return `${ day.day }_start`;
},
finishName(day) {
return `${ day.day }_finish`;
},
openName(day) {
return `${ day.day }_open`;
},
start(day) {
return Template.instance().dayVars[day.day].start.get();
},
finish(day) {
return Template.instance().dayVars[day.day].finish.get();
},
name(day) {
return TAPi18n.__(day.day);
},
open(day) {
return Template.instance().dayVars[day.day].open.get();
},
});

const splitDayAndPeriod = (value) => value.split('_');

Template.livechatBusinessHoursForm.events({
'change .preview-settings, keydown .preview-settings'(e, instance) {
const [day, period] = splitDayAndPeriod(e.currentTarget.name);

const newTime = moment(e.currentTarget.value, 'HH:mm');

// check if start and stop do not cross
if (period === 'start') {
if (newTime.isSameOrBefore(moment(instance.dayVars[day].finish.get(), 'HH:mm'))) {
instance.dayVars[day].start.set(e.currentTarget.value);
} else {
e.currentTarget.value = instance.dayVars[day].start.get();
}
} else if (period === 'finish') {
if (newTime.isSameOrAfter(moment(instance.dayVars[day].start.get(), 'HH:mm'))) {
instance.dayVars[day].finish.set(e.currentTarget.value);
} else {
e.currentTarget.value = instance.dayVars[day].finish.get();
}
}
},
'change .dayOpenCheck input'(e, instance) {
const [day, period] = splitDayAndPeriod(e.currentTarget.name);
instance.dayVars[day][period].set(e.target.checked);
},
'change .preview-settings, keyup .preview-settings'(e, instance) {
let { value } = e.currentTarget;
if (e.currentTarget.type === 'radio') {
value = value === 'true';
instance[e.currentTarget.name].set(value);
}
},
'submit .rocket-form'(e, instance) {
e.preventDefault();

// convert all times to utc then update them in db
const days = [];
for (const d in instance.dayVars) {
if (instance.dayVars.hasOwnProperty(d)) {
const day = instance.dayVars[d];
const start = moment(day.start.get(), 'HH:mm').format('HH:mm');
const finish = moment(day.finish.get(), 'HH:mm').format('HH:mm');
days.push({
day: d,
start,
finish,
open: day.open.get(),
});
}
}
Meteor.call('livechat:saveBusinessHour', {
...instance.businessHour.get(),
workHours: days,
}, function(err /* ,result*/) {
if (err) {
return handleError(err);
}
toastr.success(t('Business_hours_updated'));
});
},
});

const createDefaultBusinessHour = () => {
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const closedDays = ['Saturday', 'Sunday'];
return {
workHours: days.map((day) => ({
day,
start: '00:00',
finish: '00:00',
open: !closedDays.includes(day),
})),
};
};


Template.livechatBusinessHoursForm.onCreated(async function() {
this.dayVars = createDefaultBusinessHour().workHours.reduce((acc, day) => {
acc[day.day] = {
start: new ReactiveVar(day.start),
finish: new ReactiveVar(day.finish),
open: new ReactiveVar(day.open),
};
return acc;
}, {});
this.businessHour = new ReactiveVar({});

const { businessHour } = await APIClient.v1.get('livechat/business-hour');
this.businessHour.set({
...createDefaultBusinessHour(),
});
if (businessHour) {
this.businessHour.set(businessHour);
businessHour.workHours.forEach((d) => {
if (businessHour.timezone.name) {
this.dayVars[d.day].start.set(moment.utc(d.start.utc.time, 'HH:mm').tz(businessHour.timezone.name).format('HH:mm'));
this.dayVars[d.day].finish.set(moment.utc(d.finish.utc.time, 'HH:mm').tz(businessHour.timezone.name).format('HH:mm'));
} else {
this.dayVars[d.day].start.set(moment.utc(d.start.utc.time, 'HH:mm').local().format('HH:mm'));
this.dayVars[d.day].finish.set(moment.utc(d.finish.utc.time, 'HH:mm').local().format('HH:mm'));
}
this.dayVars[d.day].open.set(d.open);
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template name="livechatMainBusinessHours">
{{#requiresPermission 'view-livechat-business-hours'}}
<div class="livechat-businessHours-div">
{{> Template.dynamic template=getTemplate}}
</div>
{{/requiresPermission}}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Template } from 'meteor/templating';

import './livechatMainBusinessHours.html';
import { businessHourManager } from './BusinessHours';

Template.livechatMainBusinessHours.helpers({
getTemplate() {
return businessHourManager.getTemplate();
},
});
69 changes: 0 additions & 69 deletions app/livechat/client/views/app/livechatOfficeHours.html

This file was deleted.

Loading