Skip to content

Commit 5e9be4f

Browse files
authored
Merge pull request #36 from BuildFire/feat/new-suggestion-permissions
Feat/new suggestion permissions
2 parents c2c4f05 + 926f0b2 commit 5e9be4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+10879
-5617
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
control/tests/*

.eslintrc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"extends": ["eslint:recommended", "airbnb-base"],
3+
"rules": {
4+
"semi": [2, "always"],
5+
"no-underscore-dangle": 0,
6+
"no-param-reassign": 0,
7+
"max-classes-per-file": 0,
8+
"no-unused-vars": 0,
9+
"no-undef": 0,
10+
"no-console": 0,
11+
"no-prototype-builtins": 0,
12+
"no-use-before-define": 0,
13+
"consistent-return": 0,
14+
"class-methods-use-this": 0,
15+
"no-throw-literal": 0,
16+
"max-len": 0,
17+
"array-callback-return": 0,
18+
"no-plusplus": 0,
19+
"no-shadow": 0,
20+
"no-unused-expressions": 0,
21+
"no-mixed-operators": 0,
22+
"radix": 0,
23+
"no-template-curly-in-string": 0,
24+
"no-nested-ternary": 0,
25+
"prefer-destructuring": 0,
26+
"no-case-declarations": 0,
27+
"default-case": 0,
28+
"new-cap": 0,
29+
"default-param-last": 0,
30+
"prefer-promise-reject-errors": 0,
31+
"implicit-arrow-linebreak": 0,
32+
"camelcase": 0,
33+
"func-names": 0,
34+
"no-restricted-syntax": 0,
35+
"no-bitwise": 0,
36+
"guard-for-in": 0
37+
},
38+
"parserOptions": {
39+
"ecmaVersion": 2022,
40+
"sourceType": "module"
41+
},
42+
"env": {
43+
"browser": true,
44+
"node": true,
45+
"es6": true
46+
},
47+
"globals": {
48+
"buildfire": true,
49+
"tinymce": true,
50+
"mdc": true,
51+
"Setting": true,
52+
"AuthManager": true
53+
}
54+
}

control/content/index.html

Lines changed: 27 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,42 @@
22
<html>
33

44
<head>
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66

7-
<link href="../../../../styles/helper.css" rel="stylesheet">
8-
<link href="../../../../styles/siteIcons.css" rel="stylesheet">
9-
<link rel="stylesheet" href="../assets/control.css">
7+
<link href="../../../../styles/helper.css" rel="stylesheet">
8+
<link href="../../../../styles/siteIcons.css" rel="stylesheet">
109

11-
<!-- JS -->
12-
<script src="../../../../scripts/buildfire.min.js"></script>
10+
<!-- build:bundleControlAssetsCSSFiles -->
11+
<link rel="stylesheet" href="../assets/control.css">
12+
<!-- endbuild -->
1313

14-
<!-- build:bundleSharedJSFiles -->
15-
<script src="../../widget/assets/js/Analytics.js"></script>
16-
<script src="../../widget/assets/js/analyticsKeys.js"></script>
17-
<!-- endbuild -->
14+
<!-- JS -->
15+
<script src="../../../../scripts/buildfire.min.js"></script>
1816

19-
<!-- WYSIWYG -->
20-
<script src="../../../../scripts/tinymce/tinymce.min.js"></script>
17+
<!-- build:bundleSharedJSFiles -->
18+
<script src="../../widget/global/js/constants/index.js"></script>
19+
<script src="../../widget/global/js/models/Setting.js"></script>
20+
<script src="../../widget/global/js/repositories/Settings.js"></script>
21+
<script src="../../widget/global/js/services/Analyutics.js"></script>
22+
<!-- endbuild -->
2123

24+
<!-- build:bundleJSFiles -->
25+
<script src="js/content.controller.js"></script>
26+
<script src="js/state.js"></script>
27+
<script src="js/index.js"></script>
28+
<!-- endbuild -->
2229

23-
<link href="../../../../styles/control/bf-base.css" rel="stylesheet">
24-
<script>
25-
Analytics.init();
2630

27-
const debounce = (func, wait) => {
28-
let timeout;
29-
function executedFunction(...args) {
30-
const later = () => {
31-
clearTimeout(timeout);
32-
func(...args);
33-
};
34-
35-
clearTimeout(timeout);
36-
timeout = setTimeout(later, wait);
37-
};
38-
executedFunction();
39-
};
40-
41-
tinymce.init({
42-
selector: "#text",
43-
max_chars: 800,
44-
toolbar: "",
45-
plugins: "",
46-
setup: function (editor) {
47-
var data = {};
48-
editor.on("load", function () {
49-
buildfire.datastore.get(function (err, obj) {
50-
if (!obj || !obj.data) return;
51-
// This way, we will keep old instances to use PSW navigate by default (so we don't break backward compatibility) and new instances to navigate to CW by default.
52-
if (!Object.keys(obj.data).length) obj.data.navigateToCwByDefault = true;
53-
if (!obj.data.text) obj.data.text = '';
54-
55-
data = obj.data;
56-
tinymce.activeEditor.setContent(obj.data.text);
57-
});
58-
});
59-
editor.on("keyup", function (saveWithDelay) {
60-
debounce(function () {
61-
data.text = tinymce.activeEditor.getContent();
62-
save(data);
63-
}, 500);
64-
});
65-
editor.on("keydown", function (e) {
66-
var whitelistedKeys = [8, 37, 38, 39, 40, 46];
67-
if (whitelistedKeys.indexOf(e.keyCode) > -1) return true;
68-
if (tinymce_getContentLength() + 1 > this.settings.max_chars) {
69-
e.preventDefault();
70-
e.stopPropagation();
71-
return false;
72-
}
73-
return true;
74-
})
75-
editor.on("change", function (saveWithDelay) {
76-
debounce(function () {
77-
data.text = tinymce.activeEditor.getContent();
78-
save(data);
79-
}, 500);
80-
});
81-
function tinymce_getContentLength() {
82-
return tinymce.get(tinymce.activeEditor.id).contentDocument.body.innerText.length;
83-
}
84-
}
85-
});
86-
</script>
31+
<script src="../../../../scripts/tinymce/tinymce.min.js"></script>
32+
<link href="../../../../styles/control/bf-base.css" rel="stylesheet">
8733
</head>
8834

89-
<body>
90-
<div>
91-
<h1>Introduction</h1>
92-
<textarea id="text" ui-tinymce="editorOptions" class="form-control" rows="5" width="100%" height="300px"></textarea>
93-
94-
</div>
95-
96-
97-
<script>
98-
function save(data) {
99-
buildfire.datastore.save(data, function (err) {
100-
if (err) console.error(err);
101-
});
102-
}
103-
</script>
104-
35+
<body class="hidden">
36+
<div>
37+
<h1>Introduction</h1>
38+
<textarea id="introduction" class="form-control"></textarea>
39+
</div>
10540
</body>
10641

42+
10743
</html>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const contentController = {
2+
saveSettings(settings) {
3+
return new Promise((resolve, reject) => {
4+
Settings.save(settings).then(resolve).catch(reject);
5+
});
6+
},
7+
8+
getSettings() {
9+
return new Promise((resolve) => {
10+
Settings.get().then((result) => {
11+
if (!result || !Object.keys(result).length) {
12+
Analytics.init(); // init analytics only for the first time of installing the plugin
13+
Settings.save(new Setting({ navigateToCwByDefault: true })).then((settings) => {
14+
state.settings = new Setting();
15+
resolve();
16+
}).catch((err) => { // don't blok the ui, just print the error and resolve
17+
console.error(err);
18+
resolve();
19+
});
20+
} else if (result.hasOwnProperty('selectedPurchaseProductId') && result.hasOwnProperty('votesCountPerPurchase')) {
21+
Settings.unifyOldSettingsData().then((unifiedSettings) => {
22+
Settings.save(new Setting(unifiedSettings)).then(() => {
23+
state.settings = unifiedSettings;
24+
resolve();
25+
}).catch((err) => { // don't blok the ui, just print the error and resolve
26+
console.error(err);
27+
resolve();
28+
});
29+
}).catch((err) => { // don't blok the ui, just print the error and resolve
30+
console.error(err);
31+
resolve();
32+
});
33+
} else {
34+
state.settings = new Setting(result);
35+
resolve();
36+
}
37+
}).catch((err) => { // don't blok the ui, just print the error and resolve
38+
console.error(err);
39+
resolve();
40+
});
41+
});
42+
},
43+
44+
};

control/content/js/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const contentPage = {
2+
saveTimer: null,
3+
saveWithDelay() {
4+
clearTimeout(this.saveTimer);
5+
this.saveTimer = setTimeout(() => {
6+
contentController.saveSettings(state.settings);
7+
8+
buildfire.messaging.sendMessageToWidget({
9+
scope: 'introduction',
10+
introduction: state.settings.introduction,
11+
});
12+
}, 500);
13+
},
14+
15+
initWYSIWYG() {
16+
tinymce.init({
17+
selector: '#introduction',
18+
setup(editor) {
19+
editor.on('init', () => {
20+
tinymce.activeEditor.setContent(state.settings.introduction);
21+
});
22+
editor.on('keyup change', () => {
23+
state.settings.introduction = tinymce.activeEditor.getContent();
24+
contentPage.saveWithDelay();
25+
});
26+
},
27+
});
28+
},
29+
30+
init() {
31+
contentController.getSettings().then(() => {
32+
this.initWYSIWYG();
33+
document.body.classList.remove('hidden');
34+
}).catch((err) => {
35+
console.error(err);
36+
});
37+
},
38+
};
39+
40+
window.onload = () => {
41+
contentPage.init();
42+
};

control/content/js/state.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const state = {
2+
settings: new Setting(),
3+
};

0 commit comments

Comments
 (0)