From 34f0fa5da0406d419a84a23e8e39dd7fb2189ef0 Mon Sep 17 00:00:00 2001 From: Hyo Date: Thu, 15 Sep 2022 23:53:26 +0900 Subject: [PATCH 1/2] Update slack.tpl https://stackabuse.com/bytes/fix-require-is-not-defined-in-javascript-node --- public/templates/admin/plugins/slack.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/templates/admin/plugins/slack.tpl b/public/templates/admin/plugins/slack.tpl index 84b5e9b..ac647a8 100755 --- a/public/templates/admin/plugins/slack.tpl +++ b/public/templates/admin/plugins/slack.tpl @@ -42,7 +42,7 @@ - \ No newline at end of file + From 5e680dae12ef41a788ca176cc58f342cd8707b0e Mon Sep 17 00:00:00 2001 From: hyochan Date: Sat, 17 Sep 2022 20:41:13 +0900 Subject: [PATCH 2/2] fix: migrate plugin to 2.x --- plugin.json | 22 +++++++--- public/admin.js | 52 ++++++++++++++++++++++++ public/templates/admin/plugins/slack.tpl | 43 -------------------- 3 files changed, 69 insertions(+), 48 deletions(-) create mode 100644 public/admin.js diff --git a/plugin.json b/plugin.json index 98a2d8a..8834676 100755 --- a/plugin.json +++ b/plugin.json @@ -1,13 +1,25 @@ { "id": "nodebb-plugin-slack-extended", "name": "Slack Integration", - "description": "Posts new posts via Slack webhooks", + "description": "Posts new post via Slack webhooks", "url": "https://github.com/pichalite/nodebb-plugin-slack-extended.git", "library": "./library.js", "hooks": [ - { "hook": "static:app.load", "method": "init" }, - { "hook": "filter:admin.header.build", "method": "adminMenu" }, - { "hook": "action:post.save", "method": "postSave"} + { + "hook": "static:app.load", + "method": "init" + }, + { + "hook": "filter:admin.header.build", + "method": "adminMenu" + }, + { + "hook": "action:post.save", + "method": "postSave" + } ], - "templates": "./public/templates" + "templates": "./public/templates", + "modules": { + "../admin/plugins/slack.js": "public/admin.js" + } } \ No newline at end of file diff --git a/public/admin.js b/public/admin.js new file mode 100644 index 0000000..10293a7 --- /dev/null +++ b/public/admin.js @@ -0,0 +1,52 @@ +/* globals app, $, socket, define */ + +'use strict'; + +define('admin/plugins/slack', ['settings'], function (settings) { + var Slack = {}; + + $(document).ready(function() { + var categories = null; + + function addOptionsToAllSelects() { + $('.form-control.slack-category').each(function(index, element) { + addOptionsToSelect($(element)); + }); + } + + function addOptionsToSelect(select) { + for(var i=0; i' + categories[i].name + ''); + } + } + + socket.emit('categories.get', function(err, data) { + categories = data; + addOptionsToAllSelects(); + }); + }); + + Slack.init = function () { + settings.load('slack', $('.slack-settings')); + + $('#save').on('click', function () { + Promise.all([ + new Promise((resolve, reject) => { + settings.save('slack', $('.slack-settings'), err => (!err ? resolve() : reject(err))); + }), + ]).then(() => { + app.alert({ + type: 'success', + alert_id: 'slack-saved', + title: 'Settings Saved', + message: 'Please reload your NodeBB to apply these settings', + clickfn: function() { + socket.emit('admin.reload'); + } + }); + }).catch(app.alertError); + }); + }; + + return Slack; +}); diff --git a/public/templates/admin/plugins/slack.tpl b/public/templates/admin/plugins/slack.tpl index ac647a8..8c18fb4 100755 --- a/public/templates/admin/plugins/slack.tpl +++ b/public/templates/admin/plugins/slack.tpl @@ -41,46 +41,3 @@ - -