mirror of
https://github.com/wekan/wekan.git
synced 2026-01-21 08:46:09 +01:00
Add Feature: enable two-way webhooks - stage one
This commit is contained in:
parent
f3147af2f7
commit
3f0600fed7
9 changed files with 115 additions and 49 deletions
|
|
@ -1,6 +1,8 @@
|
|||
Sidebar = null;
|
||||
|
||||
const defaultView = 'home';
|
||||
const MCB = '.materialCheckBox';
|
||||
const CKCLS = 'is-checked';
|
||||
|
||||
const viewTitles = {
|
||||
filter: 'filter-cards',
|
||||
|
|
@ -280,44 +282,71 @@ Template.membersWidget.events({
|
|||
});
|
||||
|
||||
BlazeComponent.extendComponent({
|
||||
boardId() {
|
||||
return Session.get('currentBoard') || Integrations.Const.GLOBAL_WEBHOOK_ID;
|
||||
},
|
||||
integrations() {
|
||||
const boardId = Session.get('currentBoard');
|
||||
const boardId = this.boardId();
|
||||
return Integrations.find({ boardId: `${boardId}` }).fetch();
|
||||
},
|
||||
|
||||
integration(id) {
|
||||
const boardId = Session.get('currentBoard');
|
||||
return Integrations.findOne({ _id: id, boardId: `${boardId}` });
|
||||
types() {
|
||||
return Integrations.Const.WEBHOOK_TYPES;
|
||||
},
|
||||
integration(cond) {
|
||||
const boardId = this.boardId();
|
||||
const condition = { boardId, ...cond };
|
||||
for (const k in condition) {
|
||||
if (!condition[k]) delete condition[k];
|
||||
}
|
||||
return Integrations.findOne(condition);
|
||||
},
|
||||
onCreated() {
|
||||
this.disabled = new ReactiveVar(false);
|
||||
},
|
||||
|
||||
events() {
|
||||
return [
|
||||
{
|
||||
'click a.flex'(evt) {
|
||||
this.disabled.set(!this.disabled.get());
|
||||
$(evt.target).toggleClass(CKCLS, this.disabled.get());
|
||||
},
|
||||
submit(evt) {
|
||||
evt.preventDefault();
|
||||
const url = evt.target.url.value;
|
||||
const boardId = Session.get('currentBoard');
|
||||
const boardId = this.boardId();
|
||||
let id = null;
|
||||
let integration = null;
|
||||
const title = evt.target.title.value;
|
||||
const token = evt.target.token.value;
|
||||
const type = evt.target.type.value;
|
||||
const enabled = !this.disabled.get();
|
||||
let remove = false;
|
||||
const values = {
|
||||
url,
|
||||
type,
|
||||
token,
|
||||
title,
|
||||
enabled,
|
||||
};
|
||||
if (evt.target.id) {
|
||||
id = evt.target.id.value;
|
||||
integration = this.integration(id);
|
||||
if (url) {
|
||||
Integrations.update(integration._id, {
|
||||
$set: {
|
||||
url: `${url}`,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
Integrations.remove(integration._id);
|
||||
}
|
||||
integration = this.integration({ _id: id });
|
||||
remove = !url;
|
||||
} else if (url) {
|
||||
integration = this.integration({ url, token });
|
||||
}
|
||||
if (remove) {
|
||||
Integrations.remove(integration._id);
|
||||
} else if (integration && integration._id) {
|
||||
Integrations.update(integration._id, {
|
||||
$set: values,
|
||||
});
|
||||
} else if (url) {
|
||||
Integrations.insert({
|
||||
...values,
|
||||
userId: Meteor.userId(),
|
||||
enabled: true,
|
||||
type: 'outgoing-webhooks',
|
||||
url: `${url}`,
|
||||
boardId: `${boardId}`,
|
||||
boardId,
|
||||
activities: ['all'],
|
||||
});
|
||||
}
|
||||
|
|
@ -474,12 +503,12 @@ BlazeComponent.extendComponent({
|
|||
evt.preventDefault();
|
||||
this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
|
||||
this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
|
||||
$('.js-field-has-subtasks .materialCheckBox').toggleClass(
|
||||
'is-checked',
|
||||
$(`.js-field-has-subtasks ${MCB}`).toggleClass(
|
||||
CKCLS,
|
||||
this.currentBoard.allowsSubtasks,
|
||||
);
|
||||
$('.js-field-has-subtasks').toggleClass(
|
||||
'is-checked',
|
||||
CKCLS,
|
||||
this.currentBoard.allowsSubtasks,
|
||||
);
|
||||
$('.js-field-deposit-board').prop(
|
||||
|
|
@ -515,15 +544,12 @@ BlazeComponent.extendComponent({
|
|||
];
|
||||
options.forEach(function(element) {
|
||||
if (element !== value) {
|
||||
$(`#${element} .materialCheckBox`).toggleClass(
|
||||
'is-checked',
|
||||
false,
|
||||
);
|
||||
$(`#${element}`).toggleClass('is-checked', false);
|
||||
$(`#${element} ${MCB}`).toggleClass(CKCLS, false);
|
||||
$(`#${element}`).toggleClass(CKCLS, false);
|
||||
}
|
||||
});
|
||||
$(`#${value} .materialCheckBox`).toggleClass('is-checked', true);
|
||||
$(`#${value}`).toggleClass('is-checked', true);
|
||||
$(`#${value} ${MCB}`).toggleClass(CKCLS, true);
|
||||
$(`#${value}`).toggleClass(CKCLS, true);
|
||||
this.currentBoard.setPresentParentTask(value);
|
||||
evt.preventDefault();
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue