Skip to content

Commit 3d6efdf

Browse files
committed
Updated scripts to work with Kanban Tool SDK
1 parent 401a46e commit 3d6efdf

44 files changed

Lines changed: 329 additions & 832 deletions

Some content is hidden

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

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ Please select scripts from the table below, and copy-paste the URLs.
1313

1414
Name | Description | Configuration | `___ Copy links from this column ___`
1515
--- | --- | --- | ---
16-
[High contrast](high-contrast/) | White-on-Black boards. Useful for TV screens. | Needs to be enabled from the tools menu | [/scripts/high-contrast/high-contrast.js](https://kanbantool.com/scripts/high-contrast/high-contrast.js)
17-
[Large font](large-font/) | Makes the font on cards slightly larger. | No configuration required. | Medium font:<br/>[/scripts/large-font/medium-font.css](https://kanbantool.com/scripts/large-font/medium-font.css) <br/> Large font:<br/> [/scripts/large-font/large-font.css](https://kanbantool.com/scripts/large-font/large-font.css)
18-
[Card tilt](card-tilt/) | More natural alignment of cards. | No configuration required. | [/scripts/card-tilt/card-tilt.js](https://kanbantool.com/scripts/card-tilt/card-tilt.js)
19-
[Delete all](delete-all/) | Adds delete all option to the context menu. | No configuration required. | [/scripts/delete-all/delete-all.js](https://kanbantool.com/scripts/delete-all/delete-all.js)
20-
[Sorting animations](sorting-animations) | Animates cards when they are being moved. | No configuration required. | [/scripts/sorting-animations/sorting-animations.css](https://kanbantool.com/scripts/sorting-animations/sorting-animations.css)
21-
[Fixed cards height](fixed-cards-height) | Makes all cards the same height. | For better results you can append script [/scripts/fixed-cards-height/fixed-cards-height.js](https://kanbantool.com/scripts/fixed-cards-height/fixed-cards-height.js) | [/scripts/fixed-cards-height/medium-cards.css](https://kanbantool.com/scripts/fixed-cards-height/medium-cards.css)
22-
[Save and done](save-done/) | Adds "Save and move to done" option to the context menu. | No configuration required. | [/scripts/save-done/save-done.js](https://kanbantool.com/scripts/save-done/save-done.js)
23-
[Task done](task-done/) | Adds "Task done" option to the context menu | No configuration required. | [/scripts/task-done/task-done.js](https://kanbantool.com/scripts/task-done/task-done.js)
24-
[Change column](change-column/) | Adds change column option to the context menu. | No configuration required. | [/scripts/change-column/change-column.js](https://kanbantool.com/scripts/change-column/change-column.js)
25-
[Working time](working-time/) | Display time elapsed from when task was created. | No configuration required. | [/scripts/working-time/working-time.js](https://kanbantool.com/scripts/working-time/working-time.js)
26-
[Swimlane height](swimlane-height/) | Reduces minimal swimlane height. | No configuration required. | [/scripts/swimlane-height/min-swimlane-height.js](https://kanbantool.com/scripts/swimlane-height/min-swimlane-height.js)
27-
[Kanbanira](kanbanira/) | Basic integration with JIRA. | Needs information about JIRA project, see [README](/scripts/kanbanira/README.md) | [/scripts/kanbanira/kanbanira.js](https://kanbantool.com/scripts/kanbanira/kanbanira.js)
28-
[My activity](my-activity/) | Shows all activities in the "Team activity" widget. | No configuration required. | [/scripts/my-activity/my-activity.js](https://kanbantool.com/scripts/my-activity/my-activity.js)
16+
[High contrast](high-contrast/) | White-on-Black boards. Useful for TV screens. | Needs to be enabled from the tools menu | [/scripts/high-contrast/high-contrast.js](/scripts/high-contrast/high-contrast.js)
17+
[Large font](large-font/) | Makes the font on cards slightly larger. | No configuration required. | Medium font:<br/>[/scripts/large-font/medium-font.css](/scripts/large-font/medium-font.css) <br/> Large font:<br/> [/scripts/large-font/large-font.css](/scripts/large-font/large-font.css)
18+
[Card tilt](card-tilt/) | More natural alignment of cards. | No configuration required. | [/scripts/card-tilt/card-tilt.js](/scripts/card-tilt/card-tilt.js)
19+
[Delete all](delete-all/) | Adds delete all option to the context menu. | No configuration required. | [/scripts/delete-all/delete-all.js](/scripts/delete-all/delete-all.js)
20+
[Sorting animations](sorting-animations) | Animates cards when they are being moved. | No configuration required. | [/scripts/sorting-animations/sorting-animations.css](/scripts/sorting-animations/sorting-animations.css)
21+
[Fixed cards height](fixed-cards-height) | Makes all cards the same height. | For better results you can append script [/scripts/fixed-cards-height/fixed-cards-height.js](/scripts/fixed-cards-height/fixed-cards-height.js) | [/scripts/fixed-cards-height/medium-cards.css](/scripts/fixed-cards-height/medium-cards.css)
22+
[Save and done](save-done/) | Adds "Save and move to done" option to the context menu. | No configuration required. | [/scripts/save-done/save-done.js](/scripts/save-done/save-done.js)
23+
[Task done](task-done/) | Adds "Task done" option to the context menu | No configuration required. | [/scripts/task-done/task-done.js](/scripts/task-done/task-done.js)
24+
[Change column](change-column/) | Adds change column option to the context menu. | No configuration required. | [/scripts/change-column/change-column.js](/scripts/change-column/change-column.js)
25+
[Cycle time](cycle-time/) | Display time elapsed from when task was created. | No configuration required. | [/scripts/cycle-time/cycle-time.js](/scripts/working-time/working-time.js)
26+
[Kanbanira](kanbanira/) | Basic integration with JIRA. | Needs information about JIRA project, see [README](/scripts/kanbanira/README.md) | [/scripts/kanbanira/kanbanira.js](/scripts/kanbanira/kanbanira.js)

card-tilt/card-tilt.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
(function() {
22
var rotateTask;
33

4-
rotateTask = function(task) {
4+
rotateTask = function(taskElement) {
55
var rd;
6-
rd = ((task.model.attributes.board_version + task.model.attributes.id) % 7) - 3;
7-
task.$el.css({
6+
rd = ((taskElement.props.task.get('board_version') + taskElement.props.task.get('id')) % 7) - 3;
7+
taskElement.kt.$el.css({
88
'-webkit-transform': 'rotate(' + rd + 'deg)',
99
'-moz-transform': 'rotate(' + rd + 'deg)',
1010
'-ms-transform': 'rotate(' + rd + 'deg)',
1111
'-o-transform': 'rotate(' + rd + 'deg)',
1212
'transform': 'rotate(' + rd + 'deg)'
1313
});
1414
rd = -1 * rd;
15-
return task.$el.find('.task_name').css({
15+
return taskElement.kt.$el.find('.kt-task-body').css({
1616
'-webkit-transform': 'rotate(' + rd + 'deg)',
1717
'-moz-transform': 'rotate(' + rd + 'deg)',
1818
'-ms-transform': 'rotate(' + rd + 'deg)',
@@ -21,10 +21,15 @@
2121
});
2222
};
2323

24-
window.board.on('task:render', rotateTask);
25-
26-
setTimeout(function() {
27-
return window.board.tasks.each(rotateTask);
28-
}, 750);
24+
$(window).on('kt-task:render', function(e) {
25+
return rotateTask(e.target);
26+
});
2927

28+
KT.onInit(function() {
29+
return setTimeout(function() {
30+
return $('kt-task').each(function() {
31+
return rotateTask(this);
32+
});
33+
}, 750);
34+
});
3035
}).call(this);

card-tilt/src/card-tilt.coffee

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
rotateTask = (task) ->
1+
rotateTask = (taskElement) ->
22
# Rotate somewhere between -4deg and 4deg
3-
rd = ((task.model.attributes.board_version + task.model.attributes.id) % 7) - 3
3+
rd = ((taskElement.props.task.get('board_version') + taskElement.props.task.get('id')) % 7) - 3
44

5-
task.$el.css(
5+
taskElement.kt.$el.css(
66
'-webkit-transform': 'rotate('+rd+'deg)'
77
'-moz-transform': 'rotate('+rd+'deg)'
88
'-ms-transform': 'rotate('+rd+'deg)'
@@ -12,16 +12,17 @@ rotateTask = (task) ->
1212

1313
rd = -1 * rd
1414

15-
task.$el.find('.task_name').css(
15+
taskElement.kt.$el.find('.kt-task-body').css(
1616
'-webkit-transform': 'rotate('+rd+'deg)'
1717
'-moz-transform': 'rotate('+rd+'deg)'
1818
'-ms-transform': 'rotate('+rd+'deg)'
1919
'-o-transform': 'rotate('+rd+'deg)'
2020
'transform': 'rotate('+rd+'deg)'
2121
)
2222

23-
window.board.on 'task:render', rotateTask
23+
$(window).on 'kt-task:render', (e) -> rotateTask(e.target)
2424

25-
setTimeout ->
26-
window.board.tasks.each rotateTask
27-
, 750
25+
KT.onInit ->
26+
setTimeout ->
27+
$('kt-task').each -> rotateTask(@)
28+
, 750

change-column/change-column.js

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,28 @@
1-
(function() {
2-
var board_id, css,
3-
_this = this;
4-
5-
board_id = window.board.model.id;
6-
7-
css = " .contextMenu li.change_column >a { background-image: url('/images/icons/silk/note_go.png'); } .change_column_opts li a { background-image: url('/images/icons/silk/note.png'); } ";
8-
9-
if (window.board.model.users.get(KanbanTool.Board.current_user_id).can('move_tasks', window.board.model)) {
10-
$('<style>').html(css).appendTo('head');
11-
$.ajax({
12-
type: 'GET',
13-
url: '/boards/' + parseInt(board_id + 20) + '/schema.json',
14-
async: false,
15-
dataType: 'json',
16-
success: function(schema) {
17-
var columns, max_width;
18-
max_width = 120;
19-
columns = '<ul class="level2 change_column_opts">';
20-
$(schema.workflow_stages).each(function(i, e) {
21-
var width;
22-
columns += '<li><a href="#extension:change_column:' + e.id + '">' + e.full_name + '</a></li>';
23-
width = e.full_name.length * 6 + 30;
24-
if (width > max_width) {
25-
return max_width = width;
26-
}
27-
});
28-
columns += '</ul>';
29-
$('#task_context_menu .change_board').after('<li class="change_column has_submenu"><a onclick="return false;" href="#">Change column</a>' + columns + '</li>');
30-
return $('.change_column_opts').css({
31-
'width': max_width
32-
});
33-
}
34-
});
35-
$(window).bind('extensionContextMenuAction', function(event, action, el, pos) {
36-
var current_ws_id, task_id, ws_id;
37-
if (/extension:change_column:([0-9])/.test(action)) {
38-
ws_id = action.replace(/extension:change_column:/, '');
39-
current_ws_id = $(el).parent()[0].id.split('_')[1];
40-
task_id = $(el)[0].id.split('_')[1];
41-
if (ws_id !== current_ws_id) {
42-
return $.ajax({
43-
type: 'POST',
44-
url: '/boards/' + parseInt(board_id + 20) + '/tasks/' + task_id + '/change_board',
45-
dataType: 'script',
46-
async: false,
47-
data: {
48-
b_id: parseInt(board_id + 20),
49-
ws_id: ws_id,
50-
sl_id: $(el).parent()[0].id.split('_')[2],
51-
copy: false
52-
}
53-
});
54-
}
55-
}
56-
});
1+
window.KT.Elements.Task.contextMenu.push({
2+
name: 'Change column',
3+
permissions: 'update_tasks',
4+
type: 'submenu',
5+
options: (function(e) {
6+
var i, len, opts, ref, stage;
7+
opts = [];
8+
ref = e.delegateTarget.props.task.board().workflowStages().leafs();
9+
for (i = 0, len = ref.length; i < len; i++) {
10+
stage = ref[i];
11+
opts.push({
12+
id: stage.id,
13+
html: _.escape(stage.get('name')),
14+
action: (function() {
15+
var ids;
16+
ids = $('kt-task.kt-selected').map(function() {
17+
return this.props.taskId;
18+
});
19+
return KT.tasks.groupUpdate(ids, {
20+
'workflow_stage_id': this.id,
21+
'position': null
22+
});
23+
})
24+
});
5725
}
58-
59-
}).call(this);
26+
return opts;
27+
})
28+
});
Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,22 @@
1-
board_id = window.board.model.id;
2-
css = " .contextMenu li.change_column >a { background-image: url('/images/icons/silk/note_go.png'); }
3-
.change_column_opts li a { background-image: url('/images/icons/silk/note.png'); } "
1+
window.KT.Elements.Task.contextMenu.push(
2+
{
3+
name: 'Change column',
4+
permissions: 'update_tasks'
5+
type: 'submenu'
6+
options: ( (e) ->
7+
opts = []
48

5-
if window.board.model.users.get(KanbanTool.Board.current_user_id).can('move_tasks', window.board.model)
6-
$('<style>').html(css).appendTo('head')
7-
$.ajax
8-
type: 'GET'
9-
url: '/boards/' + parseInt(board_id + 20) + '/schema.json'
10-
async: false
11-
dataType: 'json'
12-
success: (schema) =>
13-
max_width = 120
14-
columns = '<ul class="level2 change_column_opts">'
15-
$(schema.workflow_stages).each (i, e) =>
16-
columns += '<li><a href="#extension:change_column:' + e.id + '">' + e.full_name + '</a></li>'
17-
width = e.full_name.length * 6 + 30
18-
max_width = width if width > max_width
19-
columns += '</ul>'
9+
for stage in e.delegateTarget.props.task.board().workflowStages().leafs()
10+
opts.push({
11+
id: stage.id,
12+
html: _.escape(stage.get('name')),
13+
action: (->
14+
ids = $('kt-task.kt-selected').map(-> @props.taskId)
15+
KT.tasks.groupUpdate(ids, {'workflow_stage_id': @id, 'position':null})
16+
)
17+
})
2018

21-
$('#task_context_menu .change_board').after('<li class="change_column has_submenu"><a onclick="return false;" href="#">Change column</a>' + columns + '</li>')
22-
$('.change_column_opts').css({'width': max_width})
23-
24-
$(window).bind 'extensionContextMenuAction', (event, action, el, pos) ->
25-
if (/extension:change_column:([0-9])/).test(action)
26-
ws_id = action.replace(/extension:change_column:/, '')
27-
current_ws_id = $(el).parent()[0].id.split('_')[1]
28-
task_id = $(el)[0].id.split('_')[1]
29-
30-
if ws_id != current_ws_id
31-
$.ajax
32-
type: 'POST'
33-
url: '/boards/' + parseInt(board_id + 20) + '/tasks/' + task_id + '/change_board'
34-
dataType: 'script'
35-
async: false
36-
data:
37-
b_id: parseInt(board_id + 20)
38-
ws_id: ws_id
39-
sl_id: $(el).parent()[0].id.split('_')[2]
40-
copy: false
19+
opts
20+
)
21+
}
22+
)

cycle-time/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Cycle time
2+
Displays the time elapsed since the task was created on front of the cards.
3+
4+
![preview](preview.png)

cycle-time/cycle-time.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(function() {
2+
var css;
3+
4+
css = ".cycle_time { font-size: 0.9em; }";
5+
6+
$('<style>').html(css).appendTo('head');
7+
8+
KT.Elements.Task.header.unshift({
9+
__: 'CTime',
10+
html: function(task, cardTemplate) {
11+
return "<span class=\"cycle_time\">" + (moment(task.attributes.created_at).fromNow()) + "</span>";
12+
}
13+
});
14+
}).call(this);

cycle-time/src/cycle-time.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
css = ".cycle_time { font-size: 0.9em; }"
2+
$('<style>').html(css).appendTo('head')
3+
4+
KT.Elements.Task.header.unshift({
5+
__: 'CTime'
6+
html: (task, cardTemplate) ->
7+
"""<span class="cycle_time">#{moment(task.attributes.created_at).fromNow()}</span>"""
8+
})

delete-all/delete-all.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
(function() {
2-
var css;
3-
4-
css = " .contextMenu li.delete_all a { background-image: url(/images/icons/silk/note_delete.png);} ";
5-
6-
if (window.board.model.users.get(KanbanTool.Board.current_user_id).can('delete_tasks', window.board.model)) {
7-
$('<style>').html(css).appendTo('head');
8-
$('#cell_context_menu').prepend('<li class="delete_all"><a href="#extension:delete_all">Delete all</a></li>');
9-
$(window).bind('extensionContextMenuAction', function(event, action, el, pos) {
10-
var cell, tasks_collection;
11-
if (action === 'extension:delete_all') {
12-
cell = $(el)[0].id.split('_');
13-
tasks_collection = window.board.model.tasks.where({
14-
"workflow_stage_id": parseInt(cell[2]),
15-
"swimlane_id": parseInt(cell[4])
16-
});
17-
return $(tasks_collection).each(function() {
18-
return this.destroy({
19-
async: false
20-
});
21-
});
22-
}
1+
window.KT.Elements.Tasklist.contextMenu.push({
2+
name: 'Delete all',
3+
permissions: 'delete_tasks',
4+
action: (function(e) {
5+
var ids;
6+
ids = $(e.delegateTarget).find('kt-task').map(function() {
7+
return this.props.taskId;
238
});
24-
}
25-
26-
}).call(this);
9+
return KT.tasks.groupUpdate(ids, {
10+
'_action': 'delete'
11+
});
12+
})
13+
});

0 commit comments

Comments
 (0)