From c2ee8829be5a91f37e64f28c239eee0de8002889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Wed, 15 Oct 2014 00:41:59 +0200 Subject: [PATCH] Refactor tg-issue-status directive: Create directives tg-issue-status-display, tg-issue-status-button, tg-issue-type-button, tg-issue-severity-button and tg-issue-priority-button --- app/coffee/modules/issues/detail.coffee | 349 ++++++++++++++++++++++++ app/partials/issues-detail.jade | 10 +- 2 files changed, 358 insertions(+), 1 deletion(-) diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index cc26cec7..eaca6e4f 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -356,6 +356,355 @@ IssueStatusDirective = () -> module.directive("tgIssueStatus", IssueStatusDirective) + +############################################################################# +## Issue status display directive +############################################################################# + +IssueStatusDisplayDirective = -> + # Display if a Issue is open or closed and its issueboard status. + # + # Example: + # tg-issue-status-display(ng-model="issue") + # + # Requirements: + # - Issue object (ng-model) + # - scope.statusById object + + template = _.template(""" + + <% if (status.is_closed) { %> + Closed + <% } else { %> + Open + <% } %> + + + <%= status.name %> + + """) # TODO: i18n + + link = ($scope, $el, $attrs) -> + render = (issue) -> + html = template({ + status: $scope.statusById[issue.status] + }) + $el.html(html) + + $scope.$watch $attrs.ngModel, (issue) -> + render(issue) if issue? + + $scope.$on "$destroy", -> + $el.off() + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgIssueStatusDisplay", IssueStatusDisplayDirective) + + +############################################################################# +## Issue status button directive +############################################################################# + +IssueStatusButtonDirective = ($rootScope, $repo) -> + # Display the status of Issue and you can edit it. + # + # Example: + # tg-issue-status-button(ng-model="issue") + # + # Requirements: + # - Issue object (ng-model) + # - scope.statusById object + + template = _.template(""" +
+ + <%= status.name %> + + status + + +
+ """) #TODO: i18n + + link = ($scope, $el, $attrs, $model) -> + render = (issue) => + status = $scope.statusById[issue.status] + + html = template({ + status: status + statuses: $scope.statusList + }) + $el.html(html) + + $el.on "click", ".status-data", (event) -> + event.preventDefault() + event.stopPropagation() + + $el.find(".pop-status").popover().open() + + $el.on "click", ".status", (event) -> + event.preventDefault() + event.stopPropagation() + target = angular.element(event.currentTarget) + + $.fn.popover().closeAll() + + issue = $model.$modelValue.clone() + issue.status = target.data("status-id") + + $model.$setViewValue(issue) + $repo.save($model.$modelValue).then -> + $rootScope.$broadcast("history:reload") + + $scope.$watch $attrs.ngModel, (issue) -> + render(issue) if issue + + $scope.$on "$destroy", -> + $el.off() + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", IssueStatusButtonDirective]) + +############################################################################# +## Issue type button directive +############################################################################# + +IssueTypeButtonDirective = ($rootScope, $repo) -> + # Display the type of Issue and you can edit it. + # + # Example: + # tg-issue-type-button(ng-model="issue") + # + # Requirements: + # - Issue object (ng-model) + # - scope.typeById object + + template = _.template(""" +
+ + <%= type.name %> + + type + + +
+ """) #TODO: i18n + + link = ($scope, $el, $attrs, $model) -> + render = (issue) => + type = $scope.typeById[issue.type] + + html = template({ + type: type + typees: $scope.typeList + }) + $el.html(html) + + $el.on "click", ".type-data", (event) -> + event.preventDefault() + event.stopPropagation() + + $el.find(".pop-type").popover().open() + + $el.on "click", ".type", (event) -> + event.preventDefault() + event.stopPropagation() + target = angular.element(event.currentTarget) + + $.fn.popover().closeAll() + + issue = $model.$modelValue.clone() + issue.type = target.data("type-id") + + $model.$setViewValue(issue) + $repo.save($model.$modelValue).then -> + $rootScope.$broadcast("history:reload") + + $scope.$watch $attrs.ngModel, (issue) -> + render(issue) if issue + + $scope.$on "$destroy", -> + $el.off() + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", IssueTypeButtonDirective]) + + +############################################################################# +## Issue severity button directive +############################################################################# + +IssueSeverityButtonDirective = ($rootScope, $repo) -> + # Display the severity of Issue and you can edit it. + # + # Example: + # tg-issue-severity-button(ng-model="issue") + # + # Requirements: + # - Issue object (ng-model) + # - scope.severityById object + + template = _.template(""" +
+ + <%= severity.name %> + + severity + + +
+ """) #TODO: i18n + + link = ($scope, $el, $attrs, $model) -> + render = (issue) => + severity = $scope.severityById[issue.severity] + + html = template({ + severity: severity + severityes: $scope.severityList + }) + $el.html(html) + + $el.on "click", ".severity-data", (event) -> + event.preventDefault() + event.stopPropagation() + + $el.find(".pop-severity").popover().open() + + $el.on "click", ".severity", (event) -> + event.preventDefault() + event.stopPropagation() + target = angular.element(event.currentTarget) + + $.fn.popover().closeAll() + + issue = $model.$modelValue.clone() + issue.severity = target.data("severity-id") + + $model.$setViewValue(issue) + $repo.save($model.$modelValue).then -> + $rootScope.$broadcast("history:reload") + + $scope.$watch $attrs.ngModel, (issue) -> + render(issue) if issue + + $scope.$on "$destroy", -> + $el.off() + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", IssueSeverityButtonDirective]) + + +############################################################################# +## Issue priority button directive +############################################################################# + +IssuePriorityButtonDirective = ($rootScope, $repo) -> + # Display the priority of Issue and you can edit it. + # + # Example: + # tg-issue-priority-button(ng-model="issue") + # + # Requirements: + # - Issue object (ng-model) + # - scope.priorityById object + + template = _.template(""" +
+ + <%= priority.name %> + + priority + + +
+ """) #TODO: i18n + + link = ($scope, $el, $attrs, $model) -> + render = (issue) => + priority = $scope.priorityById[issue.priority] + + html = template({ + priority: priority + priorityes: $scope.priorityList + }) + $el.html(html) + + $el.on "click", ".priority-data", (event) -> + event.preventDefault() + event.stopPropagation() + + $el.find(".pop-priority").popover().open() + + $el.on "click", ".priority", (event) -> + event.preventDefault() + event.stopPropagation() + target = angular.element(event.currentTarget) + + $.fn.popover().closeAll() + + issue = $model.$modelValue.clone() + issue.priority = target.data("priority-id") + + $model.$setViewValue(issue) + $repo.save($model.$modelValue).then -> + $rootScope.$broadcast("history:reload") + + $scope.$watch $attrs.ngModel, (issue) -> + render(issue) if issue + + $scope.$on "$destroy", -> + $el.off() + + return { + link: link + restrict: "EA" + require: "ngModel" + } + +module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", IssuePriorityButtonDirective]) + + ############################################################################# ## Promote Issue to US button directive ############################################################################# diff --git a/app/partials/issues-detail.jade b/app/partials/issues-detail.jade index 365623e2..3feb9052 100644 --- a/app/partials/issues-detail.jade +++ b/app/partials/issues-detail.jade @@ -41,8 +41,16 @@ block content tg-history(ng-model="issue", type="issue") sidebar.menu-secondary.sidebar - section.us-status(tg-issue-status, ng-model="issue") + section.us-status + h1(tg-issue-status-display, ng-model="issue") + tg-created-by-display.us-created-by(ng-model="issue") + tg-issue-type-button.issue-data(ng-model="issue") + tg-issue-severity-button.issue-data(ng-model="issue") + tg-issue-priority-button.issue-data(ng-model="issue") + tg-issue-status-button.issue-data(ng-model="issue") + section.us-assigned-to(tg-assigned-to, ng-model="issue") + section.watchers(tg-watchers, ng-model="issue") section.us-detail-settings