Skip to content

Commit

Permalink
issue #135 add milestone and label (label would work after gitlab rel…
Browse files Browse the repository at this point in the history
…ease)
  • Loading branch information
cnam committed Nov 27, 2016
1 parent 0c41467 commit efe9818
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 23 deletions.
11 changes: 9 additions & 2 deletions datasource/gitlab/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ func (ds GitLabDataSource) CreateLabel(project_id string, req *models.LabelReque
// mapLabelFromGitlab transforms gitlab label to kanban label
func mapLabelFromGitlab(l *gitlab.Label) *models.Label {
return &models.Label{
Color: l.Color,
Name: l.Name,
ID: l.ID,
Color: l.Color,
Name: l.Name,
Description: l.Description,
Subscribed: l.Subscribed,
OpenCardCount: l.OpenIssueCount,
ClosedCardCount: l.ClosedIssueCount,
OpenMergeRequestCount: l.OpenMergeRequestCount,
Priority: l.Priority,
}
}
13 changes: 9 additions & 4 deletions datasource/gitlab/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gitlab

import (
"fmt"

"gitlab.com/leanlabsio/kanban/models"
"gitlab.com/leanlabsio/kanban/modules/gitlab"
)
Expand Down Expand Up @@ -57,9 +58,13 @@ func mapMilestoneFromGitlab(m *gitlab.Milestone) *models.Milestone {
}

return &models.Milestone{
ID: m.ID,
State: m.State,
Title: m.Title,
DueDate: m.DueDate,
ID: m.ID,
IID: m.IID,
State: m.State,
Title: m.Title,
DueDate: m.DueDate,
Description: m.Description,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
14 changes: 12 additions & 2 deletions models/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ import (
"strconv"
)

// Label represent label
type Label struct {
Color string `json:"color"`
Name string `json:"name"`
ID int64 `json:"id"`
Color string `json:"color"`
Name string `json:"name"`
Description string `json:"description"`
OpenCardCount int `json:"open_card_count"`
ClosedCardCount int `json:"closed_card_count"`
OpenMergeRequestCount int `json:"open_merge_requests_count"`
Subscribed bool `json:"subscribed"`
Priority int `json:"priority"`
}

// Stage represent board stage
type Stage struct {
Name string
Position int
}

// LabelRequest represent request for update label
type LabelRequest struct {
Name string `json:"name"`
Color string `json:"color"`
Expand Down
12 changes: 8 additions & 4 deletions models/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package models

// Milestone represents a kanban milestone
type Milestone struct {
ID int64 `json:"id"`
State string `json:"state,omitempty"`
Title string `json:"title,omitempty"`
DueDate string `json:"due_date,omitempty"`
ID int64 `json:"id"`
IID int64 `json:"iid"`
State string `json:"state,omitempty"`
Title string `json:"title,omitempty"`
DueDate string `json:"due_date,omitempty"`
Description string `json:"description"`
UpdatedAt string `json:"updated_at"`
CreatedAt string `json:"created_at"`
}

// MilestoneRequest represents a milestone request for create, update, delete milestone on kanban
Expand Down
11 changes: 9 additions & 2 deletions modules/gitlab/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ import (
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html
type Label struct {
Color string `json:"color"`
Name string `json:"name"`
ID int64 `json:"id"`
Color string `json:"color"`
Name string `json:"name"`
Description string `json:"description"`
OpenIssueCount int `json:"open_issue_count"`
ClosedIssueCount int `json:"closed_issue_count"`
OpenMergeRequestCount int `json:"open_merge_requests_count"`
Subscribed bool `json:"subscribed"`
Priority int `json:"priority"`
}

// LabelRequest represents the available CreateLabel() and UpdateLabel() options.
Expand Down
12 changes: 8 additions & 4 deletions modules/gitlab/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import (
//
// GitLab API docs: http://doc.gitlab.com/ce/api/branches.html
type Milestone struct {
ID int64 `json:"id"`
State string `json:"state,omitempty"`
Title string `json:"title,omitempty"`
DueDate string `json:"due_date,omitempty"`
ID int64 `json:"id"`
IID int64 `json:"iid"`
State string `json:"state,omitempty"`
Title string `json:"title,omitempty"`
DueDate string `json:"due_date,omitempty"`
Description string `json:"description"`
UpdatedAt string `json:"updated_at"`
CreatedAt string `json:"created_at"`
}

// MilestoneRequest represents the available CreateMilestone() and UpdateMilestone() options.
Expand Down
4 changes: 3 additions & 1 deletion src/board/board.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@
$markdownProvider.registerPlugin(window.markdownitEmoji);
$markdownProvider.registerPlugin(window.md_twemoji_plugin);
$markdownProvider.registerPlugin(window.md_card_link_plugin)
$markdownProvider.registerPlugin(window.md_user_link_plugin);
$markdownProvider.registerPlugin(window.md_user_link_plugin)
$markdownProvider.registerPlugin(window.md_label_plugin)
$markdownProvider.registerPlugin(window.md_milestone_link_plugin);
}])
.constant('stage_regexp', /KB\[stage\]\[(\d+)\]\[(.*?)\]\[?(\d+)?\]?/)
.constant('priority_regexp', /KB\[priority\]\[(-?\d+)\]\[(.*?)\]/)
Expand Down
22 changes: 18 additions & 4 deletions src/markdown/directives/markdown.drc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
'BoardService',
'$stateParams',
'host_url',
function($sce, $markdown, BoardService, $stateParams, host_url) {
'MilestoneService',
'LabelService',
function($sce, $markdown, BoardService, $stateParams, host_url, MilestoneService, LabelService) {
return {
restrict: 'A',
scope: {
Expand All @@ -17,9 +19,21 @@
link: function(scope, element, attributes) {
scope.$watch('markdown', function(newData, oldData) {
if (newData !== undefined) {
BoardService.get($stateParams.project_path).then(function(board) {
var boardUrl = board.project.path_with_namespace;
element.html($markdown.render(newData, {host_url: host_url, board_url: boardUrl}));
var board;
var milestones;
BoardService.get($stateParams.project_path).then(function(res) {
board = res;
return MilestoneService.list(board.project.id);
}).then(function(res) {
milestones = res;
return LabelService.list(board.project.id);
}).then(function(labels){
element.html($markdown.render(newData, {
host_url: host_url,
board_url: board.project.path_with_namespace,
milestones: milestones,
labels: labels
}));
});
}
}, true);
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions src/markdown/plugins/label.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Milestone link plugin for generate link to other milestone
*/
(function(){
window.md_label_plugin = function(md) {
function label_rule(state, silent) {
var start = state.pos,
regex = /~(\d+)/,
max = state.posMax;

if (state.src.charCodeAt(start) !== 0x7E || silent) {
return false;
}

var matches = state.src.match(regex);

if (! matches) {
return false;
}

var id = matches[1];
var title = matches[0];

var label = _.find(state.env.labels, function(label) {
return label.id == id;
});

if (label) {
token = state.push('span_open', 'span');
token.attrPush(['style', 'background-color:' + label.color]);
token.attrPush(['class', 'label']);
token.nesting = 1;

token = state.push('text');
token.content = label.name;
token.nesting = 0;

token = state.push('span_open', 'span');
token.nesting = -1;
}

state.pos = start + id.length + 1;
return true;
}

md.inline.ruler.push('label_rule', label_rule);
};
}());
54 changes: 54 additions & 0 deletions src/markdown/plugins/milestone-link.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Milestone link plugin for generate link to other milestone
*/
(function(){
window.md_milestone_link_plugin = function(md) {
function milestone_rule(state, silent) {
var start = state.pos,
regex = /([a-z0-9\.-_\/]+)?%(\d+)/,
max = state.posMax;

if (state.src.charCodeAt(start) !== 0x25 || silent) {
return false;
}

var matches = state.src.match(regex);

if (! matches) {
return false;
}

var id = matches[2];
var title = matches[0];
var board_name = state.env.board_url;
if (matches[1]) {
board_name = matches[1];
state.pending = state.pending.slice(0, -matches[1].length);
}
var milestone = _.find(state.env.milestones, function(milestone) {
return milestone.iid == id;
});

token = state.push('link_open', 'a');
token.attrPush(['title', title]);
token.attrPush(['href', '/boards/' + board_name + '?tags=^' + milestone.id]);
token.attrPush(['data-link-local', '']);
token.nesting = 1;

token = state.push('text');
if (milestone) {
token.content = milestone.title;
} else {
token.content = title;
}
token.nesting = 0;

token = state.push('link_close', 'a');
token.nesting = -1;
state.pos = start + id.length + 1;
return true;
}

md.inline.ruler.push('card_rule', milestone_rule);
};
}());
File renamed without changes.

0 comments on commit efe9818

Please sign in to comment.