Skip to content

Commit 8c41ef6

Browse files
authored
Merge pull request #63 from NenoR96/toggle
Toggle
2 parents 751fe0c + 59dd2b9 commit 8c41ef6

25 files changed

Lines changed: 992 additions & 136 deletions

control/content/controllers/content.home.controller.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ContentHome.searchOptions = {
2323
filter: {"$json.title": {"$regex": '/*'}},
2424
skip: SORT._skip,
25-
limit: SORT._limit + 1 // the plus one is to check if there are any more
25+
limit: SORT._limit // the plus one is to check if there are any more
2626
};
2727

2828
/**
@@ -81,6 +81,7 @@
8181
if(data) {
8282
var item = ContentHome.items[_index];
8383
Deeplink.deleteById(item.id);
84+
buildfire.analytics.unregisterEvent(`DOCUMENT_${item.id}_OPENED`);
8485
DataStore.deleteById(item.id, TAG_NAMES.SEMINAR_ITEMS).then(function (result) {
8586
ContentHome.items.splice(_index, 1);
8687
searchOptionUserData.filter ={"$or": [{"$json.itemID": {"$eq": item.id}}]};
@@ -191,8 +192,6 @@
191192
else
192193
editor.loadItems(ContentHome.data.content.carouselImages);
193194
}
194-
if(typeof ContentHome.data.content.sortBy == "undefined")
195-
ContentHome.data.content.sortBy=SORT.MANUALLY;
196195
ContentHome.itemSortableOptions.disabled = !(ContentHome.data.content.sortBy === SORT.MANUALLY);
197196
RankOfLastItem.setRank(ContentHome.data.content.rankOfLastItem || 0);
198197
updateMasterItem(ContentHome.data);
@@ -225,17 +224,35 @@
225224
if (ContentHome.data && ContentHome.data.content.sortBy && !search) {
226225
ContentHome.searchOptions = getSearchOptions(ContentHome.data.content.sortBy);
227226
}
228-
DataStore.search(ContentHome.searchOptions, TAG_NAMES.SEMINAR_ITEMS).then(function (result) {
229-
if (result.length <= SORT._limit) {// to indicate there are more
227+
228+
DataStore.search(ContentHome.searchOptions, TAG_NAMES.SEMINAR_ITEMS).then((result) => {
229+
230+
ContentHome.items = ContentHome.items ? ContentHome.items.concat(result) : result;
231+
ContentHome.busy = false;
232+
233+
if (result.length < SORT._limit) {// to indicate there are more
230234
ContentHome.noMore = true;
231235
Buildfire.spinner.hide();
232236
} else {
233-
result.pop();
234237
ContentHome.searchOptions.skip = ContentHome.searchOptions.skip + SORT._limit;
235238
ContentHome.noMore = false;
239+
return ContentHome.loadMore(search);
236240
}
237-
ContentHome.items = ContentHome.items ? ContentHome.items.concat(result) : result;
238-
ContentHome.busy = false;
241+
242+
// Make sure Items are sorted
243+
if(typeof ContentHome.data.content.sortBy == "undefined"){
244+
return ContentHome.sortItemBy(SORT.OLDEST_FIRST)
245+
} else {
246+
// Make sure Items are ranked correctly;
247+
for(let i = 0; i < ContentHome.items.length; i++) {
248+
if (ContentHome.items[i].data.rank !== i) {
249+
ContentHome.items[i].data.rank = i;
250+
DataStore.update(ContentHome.items[i].id, ContentHome.items[i].data, TAG_NAMES.SEMINAR_ITEMS, () => {});
251+
}
252+
}
253+
}
254+
255+
if (!$scope.$$phase && !$scope.$root.$$phase) $scope.$apply();
239256
Buildfire.spinner.hide();
240257
}, function (error) {
241258
Buildfire.spinner.hide();
@@ -358,7 +375,6 @@
358375
}
359376
};
360377

361-
362378
/*
363379
* Call the datastore to save the data object
364380
*/

control/content/controllers/content.item.controller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@
173173
_data.rank = ContentItem.item.data.rank;
174174
RankOfLastItem.setRank(_rankOfLastItem);
175175
updateMasterItem(ContentItem.item);
176+
177+
buildfire.analytics.registerEvent(
178+
{
179+
title: ContentItem.item.data.title,
180+
key: `DOCUMENT_${result.id}_OPENED`,
181+
description: "Number of times this item has been opened",
182+
},
183+
{ silentNotification: true }
184+
);
185+
176186
ContentItem.item.data.deepLinkUrl = Buildfire.deeplink.createLink({ id: result.id });
177187
if (ContentItem.item.id) {
178188
buildfire.messaging.sendMessageToWidget({

control/content/enums.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
OLDEST_PUBLICATION_DATE: 'Oldest pub. date first',
4747
NEWEST_FIRST: 'Newest entry first',
4848
OLDEST_FIRST: 'Oldest entry first',
49-
_limit: 10,
50-
_maxLimit: 19,
49+
_limit: 50,
50+
_maxLimit: 50,
5151
_skip: 0
5252
});
5353
})(window.angular);

control/settings/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
(function (angular) {
33
angular
4-
.module('seminarSettings', ['ngRoute'])
4+
.module('seminarSettings', ['ngRoute', 'ui.bootstrap'])
55
.config(['$routeProvider', function ($routeProvider) {
66
$routeProvider
77
.when('/', {

control/settings/assets/css/control.settings.css

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
2+
.button-switch{
3+
display: flex;
4+
align-items: center;
5+
height: 1.5rem;
6+
}
7+
.button-switch > label {
8+
cursor: pointer;
9+
height: 0;
10+
position: relative;
11+
width: 40px;
12+
text-align: left;
13+
}
14+
15+
.button-switch > label::before {
16+
background: #909090;
17+
border-radius: 18px;
18+
content: "";
19+
height: 27px;
20+
margin-top: -13.5px;
21+
position: absolute;
22+
opacity: 0.3;
23+
transition: all 0.4s ease-in-out;
24+
width: 46px;
25+
}
26+
27+
.button-switch > label::after {
28+
background: #fff;
29+
border-radius: 16px;
30+
box-shadow: 0 0 5px rgb(0 0 0 / 30%);
31+
content: "";
32+
height: 24px;
33+
left: 0;
34+
margin-top: -9px;
35+
position: absolute;
36+
top: -3px;
37+
transition: all 0.3s ease-in-out;
38+
width: 24px;
39+
}
40+
41+
.button-switch > input[type="checkbox"]:checked + label::before {
42+
background: inherit;
43+
opacity: 0.5;
44+
}
45+
46+
.button-switch > input[type="checkbox"] {
47+
display: none;
48+
margin: 4px 0 0;
49+
}
50+
51+
.button-switch > input[type="checkbox"]:checked + label::after {
52+
background: inherit;
53+
left: 23px;
54+
}
55+
56+
.button-switch.switch-sm > input[type="checkbox"]:checked + label::after {
57+
left: 17px;
58+
}
59+
60+
.col-md-4 {
61+
padding: 0 !important;
62+
}
63+
64+
.dropdown {
65+
width: 200px;
66+
}
67+
168
.toolbar {
269
display: flex;
370
justify-content: space-between;

control/settings/controllers/settings.home.controller.js

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,117 @@
66
function ($scope, Buildfire, LAYOUTS, DataStore, TAG_NAMES) {
77
var Settings = this;
88
Settings.data = {};
9+
10+
Settings.seminarDelayOptions = [
11+
{ label: "Off", value: 0 },
12+
{ label: "Half hour", value: 30 },
13+
{ label: "One hour", value: 60 },
14+
{ label: "One Day", value: 1440 },
15+
{ label: "One Week", value: 10080 },
16+
];
17+
18+
$scope.nextSeminarDelay = false;
19+
20+
Settings.seminarLockedClassOptions = ["hidden", "locked"];
21+
922
var _data = {
1023
"content": {
1124
"carouselImages": [],
12-
"description": ""
25+
"description": "",
26+
seminarDelay: Settings.seminarDelayOptions[0],
27+
lockedClass: Settings.seminarLockedClassOptions[0]
1328
},
1429
"design": {
1530
"itemListLayout": LAYOUTS.itemListLayout[0].name,
1631
"itemListBgImage": ""
1732
}
1833
};
34+
1935
Settings.init = function () {
2036
var success = function (result) {
2137
console.info('Init success result:', result);
2238
Settings.data = result.data;
2339
if (!Settings.data) {
2440
Settings.data = angular.copy(_data);
2541
} else {
26-
if (!Settings.data.content)
27-
Settings.data.content = {};
42+
if (!Settings.data.content) {
43+
Settings.data.content = {};
44+
}
45+
46+
if (!Settings.data.content.seminarDelay) {
47+
Settings.data.content.seminarDelay = Settings.seminarDelayOptions[0];
48+
$scope.nextSeminarDelay = false;
49+
} else if(Settings.data.content.seminarDelay.value !== 0) $scope.nextSeminarDelay = true;
50+
if (!Settings.data.content.lockedClass) Settings.data.content.lockedClass = Settings.seminarLockedClassOptions[0];
2851
}
2952
},
3053
error = function (err) {
3154
console.error('Error while getting data', err);
3255
};
33-
DataStore.get(TAG_NAMES.SEMINAR_INFO).then(success, error);
56+
57+
DataStore.get(TAG_NAMES.SEMINAR_INFO).then(success, error);
3458
};
3559

36-
Settings.setAllowShare = function(check){
37-
if(Settings.data.allowSharing!=check){
38-
Settings.data.allowSharing=check;
60+
$scope.setAllowShare = function(){
3961
var success = function (result) {
4062
console.info('Data saved:', result);
4163
},
4264
error = function (err) {
4365
console.error('Error while saving data', err);
4466
};
45-
DataStore.save(Settings.data,TAG_NAMES.SEMINAR_INFO).then(success, error);
67+
DataStore.save(Settings.data,TAG_NAMES.SEMINAR_INFO).then(success, error);
68+
}
69+
70+
$scope.setSeminarSettings = () => {
71+
if($scope.nextSeminarDelay)
72+
Settings.setSeminarSettings('seminarDelay', Settings.seminarDelayOptions[1]);
73+
else Settings.setSeminarSettings('seminarDelay', Settings.seminarDelayOptions[0]);
74+
}
75+
76+
Settings.setSeminarSettings = (type, value) => {
77+
if (type === 'seminarDelay') {
78+
Settings.data.content.seminarDelay = value;
79+
} else {
80+
Settings.data.content.lockedClass = value;
4681
}
82+
83+
let success = (result) => {
84+
console.info('Data saved:', result);
85+
},
86+
error = (err) => {
87+
console.error('Error while saving data', err);
88+
};
89+
90+
DataStore.save(Settings.data, TAG_NAMES.SEMINAR_INFO).then(success, error);
4791
}
4892

93+
// Settings.getDelaySettings = (callback) => {
94+
// buildfire.appData.get("seminarDelay", (err, result) => {
95+
// if (err) return console.error('Error while getting delay settings', err);
96+
// if (result && result.data && result.data.seminarSettings) {
97+
// console.error("Result", result.data)
98+
// Settings.data.design.seminarDelay = result.data.seminarDelay;
99+
// }
100+
// callback();
101+
// });
102+
// }
103+
104+
// Settings.setDelaySettings = (type, value) => {
105+
// if (type === 'seminarDelay') {
106+
// Settings.data.design.seminarDelay = seminarDelay;
107+
// } else {
108+
109+
// }
110+
// buildfire.appData.save(
111+
// { seminarDelay },
112+
// "seminarDelay",
113+
// (err, result) => {
114+
// if (err) return console.error("Error while saving delay settings", err);
115+
// console.log("Delay settings successfully", result);
116+
// }
117+
// );
118+
// }
119+
49120
Settings.init();
50121
}
51122
])

0 commit comments

Comments
 (0)