Skip to content

Commit bfe6338

Browse files
authored
Merge pull request #40 from BuildFire/histogram
Histogram
2 parents bccf459 + 61a9b91 commit bfe6338

28 files changed

Lines changed: 223 additions & 213 deletions

File tree

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
],
77
"rules": {
88
"consistent-return": 0,
9+
"no-prototype-builtins": 0,
910
"no-return-assign": 0,
1011
"comma-dangle": 0,
1112
"no-restricted-globals": 0,

src/DataMocks/category.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/DataMocks/index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/DataMocks/location.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/UserAccessControl/authManager.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ const authManager = {
66
set currentUser(user) {
77
authManager._currentUser = user;
88
},
9+
get sanitizedCurrentUser() {
10+
if (!this.currentUser) return null;
11+
const sanitizedUser = { ...this.currentUser };
12+
13+
// the following will be stored in location createdBy
14+
if (typeof sanitizedUser._cpUser !== "undefined") {
15+
sanitizedUser.isCPUser = true;
16+
}
17+
18+
// List of properties to remove
19+
const propertiesToRemove = [
20+
"email", "username", "accessToken", "accessTokenExpiresIn",
21+
"externalApps", "lastUsedIPAddress", "userToken", "loginProviderType",
22+
"failedAttemptCount", "_cpUser",
23+
];
24+
25+
propertiesToRemove.forEach((prop) => {
26+
if (sanitizedUser.hasOwnProperty(prop)) {
27+
delete sanitizedUser[prop];
28+
}
29+
});
30+
31+
return sanitizedUser;
32+
},
933
enforceLogin(callback) {
1034
buildfire.auth.getCurrentUser((err, currentUser) => {
1135
if (!currentUser) {
@@ -33,6 +57,14 @@ const authManager = {
3357
authManager.currentUser = null;
3458
window.location.reload();
3559
}, true);
60+
},
61+
getUserProfile(userId) {
62+
return new Promise((resolve, reject) => {
63+
buildfire.auth.getUserProfile({ userId }, (err, user) => {
64+
if (err) return reject(err);
65+
resolve(user);
66+
});
67+
});
3668
}
3769
};
3870
buildfire.auth.onLogout(authManager.enforceLogin, true);

src/control/assets/bf_base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ p.info-note.info-note-transparent {
553553
}
554554

555555
.bf-tooltip:not(.hidden-tooltip) {
556+
cursor: pointer;
556557
display: inline-block;
557558
text-align: center;
558559
position: relative;

src/control/content/js/categories/controller.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Analytics from '../../../../utils/analytics';
77
export default {
88
createCategory(category) {
99
category.createdOn = new Date();
10-
category.createdBy = authManager.currentUser;
10+
category.createdBy = authManager.sanitizedCurrentUser;
1111
return Categories.create(category.toJSON()).then((result) => {
1212
Analytics.registerCategoryEvent(result.id, result.title);
1313
for (const sub of result.subcategories) {
@@ -45,38 +45,40 @@ export default {
4545
return Categories.search(options);
4646
},
4747
getAllCategories(callback) {
48-
let searchOptions = {
49-
limit: 50,
50-
skip: 0,
51-
52-
}, categories = [];
53-
48+
const options = {
49+
limit: 50,
50+
skip: 0,
51+
filter: {},
52+
sort: { title: 1 }
53+
};
54+
let categories = [];
55+
56+
options.filter["_buildfire.index.date1"] = { $type: 10 };
57+
5458
const getCategoriesData = (callback) => {
55-
Categories.search(searchOptions).then(result => {
56-
if (result.length < searchOptions.limit) {
59+
Categories.search(options).then((result) => {
60+
if (result.length < options.limit) {
5761
categories = categories.concat(result);
58-
categories = categories.filter(x => x.deletedBy == null);
5962
return callback(categories);
6063
} else {
61-
searchOptions.skip = searchOptions.skip + searchOptions.limit;
64+
options.skip = options.skip + options.limit;
6265
categories = categories.concat(result);
6366
return getCategoriesData(callback);
6467
}
6568
})
6669
}
6770

6871
getCategoriesData(callback);
69-
7072
},
7173

7274
updateCategory(categoryId, category) {
7375
category.lastUpdatedOn = new Date();
74-
category.lastUpdatedBy = authManager.currentUser;
76+
category.lastUpdatedBy = authManager.sanitizedCurrentUser;
7577
return Categories.update(categoryId, category.toJSON());
7678
},
7779
deleteCategory(categoryId, category) {
7880
category.deletedOn = new Date();
79-
category.deletedBy = authManager.currentUser;
81+
category.deletedBy = authManager.sanitizedCurrentUser;
8082
return Categories.delete(categoryId, category.toJSON());
8183
}
8284
};

src/control/content/js/categories/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,13 @@ window.importCategories = () => {
556556
let categoriesLoaded = new Set();
557557
result.forEach((item) =>{
558558
let itemCategories = item.categories.split(",");
559-
if(itemCategories?.length > 0)
559+
if(itemCategories?.length > 0)
560560
itemCategories.forEach((cat)=> {
561-
if(cat?.length > 0)
561+
if(cat?.length > 0)
562562
categoriesLoaded.add(cat.trim())
563563
});
564564
});
565-
categoriesLoaded.forEach((cat) => categories.push(new Category({title:cat,createdOn:new Date(),createdBy:authManager.currentUser}).toJSON()));
565+
categoriesLoaded.forEach((cat) => categories.push(new Category({title:cat,createdOn:new Date(),createdBy:authManager.sanitizedCurrentUser}).toJSON()));
566566
}else{
567567
categories = result.map((elem) => {
568568
delete elem.id;
@@ -571,7 +571,7 @@ window.importCategories = () => {
571571
elem.iconClassName = elem?.iconClassName?.trim();
572572
elem.subcategories = elem.subcategories?.split(',').filter((elem) => elem).map((subTitle) => ({ id: generateUUID(), title: subTitle?.trim() }));
573573
elem.createdOn = new Date();
574-
elem.createdBy = authManager.currentUser;
574+
elem.createdBy = authManager.sanitizedCurrentUser;
575575
return new Category(elem).toJSON();
576576
});
577577
}
@@ -677,7 +677,7 @@ const loadMoreCategories = () => {
677677
categoriesListUI.append(categories)
678678
isLoading = false;
679679
});
680-
}
680+
}
681681
};
682682
}
683683

src/control/content/js/listView/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
},
1010
saveSettings(settings) {
1111
settings.lastUpdatedOn = new Date();
12-
settings.lastUpdatedBy = authManager.currentUser;
12+
settings.lastUpdatedBy = authManager.sanitizedCurrentUser;
1313
return Settings.save(settings.toJSON());
1414
},
1515
};

src/control/content/js/locations/controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
createLocation(location) {
1313
location.clientId = generateUUID();
1414
location.createdOn = new Date();
15-
location.createdBy = authManager.currentUser;
15+
location.createdBy = authManager.sanitizedCurrentUser;
1616
return Location.add(location.toJSON()).then((result) => {
1717
Analytics.registerLocationViewedEvent(result.id, result.title);
1818
DeepLink.registerDeeplink(result);
@@ -40,7 +40,7 @@ export default {
4040
},
4141
updateLocation(locationId, location) {
4242
location.lastUpdatedOn = new Date();
43-
location.lastUpdatedBy = authManager.currentUser;
43+
location.lastUpdatedBy = authManager.sanitizedCurrentUser;
4444
const promiseChain = [
4545
Location.update(locationId, location.toJSON()),
4646
DeepLink.registerDeeplink(location),
@@ -67,7 +67,7 @@ export default {
6767
},
6868
saveSettings(settings) {
6969
settings.lastUpdatedOn = new Date();
70-
settings.lastUpdatedBy = authManager.currentUser;
70+
settings.lastUpdatedBy = authManager.sanitizedCurrentUser;
7171
return Settings.save(settings.toJSON());
7272
},
7373
};

0 commit comments

Comments
 (0)