Ver código fonte

Allow delete from client. List all integrations in web UI

Andrés Manelli 7 anos atrás
pai
commit
5bc95511e5

+ 15 - 5
client/components/boards/boardHeader.jade

@@ -227,11 +227,21 @@ template(name="archiveBoardPopup")
   button.js-confirm.negate.full(type="submit") {{_ 'archive'}}
 
 template(name="outgoingWebhooksPopup")
-  form
+  each integrations
+    form.integration-form
+      if title
+        h4 {{title}}
+      else
+        h4 {{_ 'no-name'}}
+      label
+        | URL
+        input.js-outgoing-webhooks-url(type="text" name="url" value=url)
+        input(type="hidden" value=_id name="id")
+      input.primary.wide(type="submit" value="{{_ 'save'}}")
+  form.integration-form
+    h4
+      | {{_ 'new-integration'}}
     label
       | URL
-      if integration.enabled
-        input.js-outgoing-webhooks-url(type="text" value=integration.url autofocus)
-      else
-        input.js-outgoing-webhooks-url(type="text" autofocus)
+      input.js-outgoing-webhooks-url(type="text" name="url" autofocus)
     input.primary.wide(type="submit" value="{{_ 'save'}}")

+ 16 - 11
client/components/boards/boardHeader.js

@@ -241,39 +241,44 @@ BlazeComponent.extendComponent({
 }).register('boardChangeWatchPopup');
 
 BlazeComponent.extendComponent({
-  integration() {
+  integrations() {
     const boardId = Session.get('currentBoard');
-    return Integrations.findOne({ boardId: `${boardId}` });
+    return Integrations.find({ boardId: `${boardId}` }).fetch();
+  },
+
+  integration(id) {
+    const boardId = Session.get('currentBoard');
+    return Integrations.findOne({ _id: id, boardId: `${boardId}` });
   },
 
   events() {
     return [{
       'submit'(evt) {
         evt.preventDefault();
-        const url = this.find('.js-outgoing-webhooks-url').value.trim();
+        const url = evt.target.url.value;
         const boardId = Session.get('currentBoard');
-        const integration = this.integration();
-        if (integration) {
+        let id = null;
+        let integration = null;
+        if (evt.target.id) {
+          id = evt.target.id.value;
+          integration = this.integration(id);
           if (url) {
             Integrations.update(integration._id, {
               $set: {
-                enabled: true,
                 url: `${url}`,
               },
             });
           } else {
-            Integrations.update(integration._id, {
-              $set: {
-                enabled: false,
-              },
-            });
+            Integrations.remove(integration._id);
           }
         } else if (url) {
           Integrations.insert({
+            userId: Meteor.userId(),
             enabled: true,
             type: 'outgoing-webhooks',
             url: `${url}`,
             boardId: `${boardId}`,
+            activities: ['all'],
           });
         }
         Popup.close();

+ 3 - 0
client/components/boards/boardHeader.styl

@@ -0,0 +1,3 @@
+.integration-form
+  padding: 5px
+  border-bottom: 1px solid #ccc

+ 2 - 0
i18n/en.i18n.json

@@ -368,6 +368,8 @@
     "error-notAuthorized": "You are not authorized to view this page.",
     "outgoing-webhooks": "Outgoing Webhooks",
     "outgoingWebhooksPopup-title": "Outgoing Webhooks",
+    "new-integration": "New integration",
+    "no-name": "(Unknown)",
     "Wekan_version": "Wekan version",
     "Node_version": "Node version",
     "OS_Arch": "OS Arch",

+ 3 - 0
models/integrations.js

@@ -50,6 +50,9 @@ Integrations.allow({
   update(userId, doc) {
     return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
   },
+  remove(userId, doc) {
+    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+  },
   fetch: ['boardId'],
 });