Implemented issue creation on issues list.

stable
Andrey Antukh 2014-07-10 20:00:38 +02:00
parent ff41e86f2b
commit 3fb545edf2
5 changed files with 130 additions and 35 deletions

View File

@ -22,22 +22,65 @@
taiga = @.taiga
bindOnce = @.taiga.bindOnce
module = angular.module("taigaIssues")
#############################################################################
## Issue Create Lightbox Directive
#############################################################################
CreateIssueDirective = ($repo, $model, $rs, $rootscope) ->
link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley()
$scope.issue = {}
$scope.$on "issueform:new", ->
$el.removeClass("hidden")
$scope.issue = {
project: $scope.projectId
subject: ""
status: $scope.project.default_issue_status
type: $scope.project.default_issue_type
priority: $scope.project.default_priority
severity: $scope.project.default_severity
estimated_start: null
estimated_finish: null
}
$scope.$on "$destroy", ->
$el.off()
submit = ->
console.log $scope.issue
if not form.validate()
return
promise = $repo.create("issues", $scope.issue)
promise.then (data) ->
$el.addClass("hidden")
console.log "succcess", data
$rootscope.$broadcast("issueform:new:success", data)
# FIXME: error handling?
promise.then null, ->
console.log "FAIL"
$el.on "click", ".close", (event) ->
event.preventDefault()
$el.addClass("hidden")
$el.on "click", ".button-green", (event) ->
event.preventDefault()
submit()
$el.on "submit", "form", (event) ->
event.preventDefault()
submit()
return {link:link}
module = angular.module("taigaIssues")
module.directive("tgLbCreateIssue", [
"$tgRepo",
"$tgModel",
@ -46,7 +89,39 @@ module.directive("tgLbCreateIssue", [
CreateIssueDirective
])
AddWatcherDirective = () ->
#############################################################################
## Issue Create Lightbox Directive
#############################################################################
# BulkCreateIssuesDirective = ($repo, $model, $rs, $rootscope) ->
# link = ($scope, $el, $attrs) ->
# $scope.$on "issueform:new", ->
# $el.removeClass("hidden")
#
# $scope.$on "$destroy", ->
# $el.off()
#
# $el.on "click", ".close", (event) ->
# event.preventDefault()
# $el.addClass("hidden")
#
# return {link:link}
# module.directive("tgLbCreateIssue", [
# "$tgRepo",
# "$tgModel",
# "$tgResources",
# "$rootScope",
# CreateIssueDirective
# ])
#############################################################################
## Watchers Lightbox directive
#############################################################################
# FIXME: rename to: WatchersLightboxDirective/tgLbWatchers
AddWatcherDirective = ->
link = ($scope, $el, $attrs) ->
$scope.usersSearch = {}
$scope.$on "watcher:add", ->
@ -72,21 +147,27 @@ AddWatcherDirective = () ->
module.directive("tgLbAddWatcher", AddWatcherDirective)
#############################################################################
## AssignedTo Lightbox Directive
#############################################################################
EditAssignedToDirective = () ->
# FIXME: rename to: AssignedToLightboxDirective/tgLbAssignedto
EditAssignedToDirective = ->
link = ($scope, $el, $attrs) ->
editingElement = null
updateScopeFilteringUsers = (searchingText) ->
usersById = _.clone($scope.usersById, false)
#Exclude selected user
# Exclude selected user
if $scope.selectedUser?
delete usersById[$scope.selectedUser.id]
#Filter text
usersById = _.filter(usersById, (user) -> _.contains(user.full_name_display, searchingText))
# Filter text
usersById = _.filter usersById, (user) ->
return _.contains(user.full_name_display, searchingText)
#Return max of 5 elements
# Return max of 5 elements
users = _.map(usersById, (user) -> user)
$scope.AssignedToUsersSearch = searchingText
$scope.filteringUsers = users.length > 5
@ -95,9 +176,11 @@ EditAssignedToDirective = () ->
$scope.$on "assigned-to:add", (ctx, element) ->
editingElement = element
assignedToId = editingElement?.assigned_to
$scope.selectedUser = null
$scope.selectedUser = $scope.usersById[assignedToId] if assignedToId?
updateScopeFilteringUsers("")
$el.removeClass("hidden")
$el.find("input").focus()
@ -117,6 +200,7 @@ EditAssignedToDirective = () ->
$el.on "click", ".remove-assigned-to", (event) ->
event.preventDefault()
event.stopPropagation()
if editingElement?
editingElement.assigned_to = null

View File

@ -56,12 +56,23 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
promise.then null, ->
console.log "FAIL" #TODO
@scope.$on "issueform:new:succcess", =>
@.loadIssues()
@.loadFilters()
loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) =>
@scope.project = project
# TODO: add issueTypeList and issueTypeById
@scope.issueStatusById = groupBy(project.issue_statuses, (x) -> x.id)
@scope.issueStatusList = _.sortBy(project.issue_statuses, "order")
@scope.severityById = groupBy(project.severities, (x) -> x.id)
@scope.severityList = _.sortBy(project.severities, "order")
@scope.priorityById = groupBy(project.priorities, (x) -> x.id)
@scope.priorityList = _.sortBy(project.priorities, "order")
console.log @scope.priorityList
@scope.membersById = groupBy(project.memberships, (x) -> x.user)
return project
@ -154,7 +165,6 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
loadIssues: ->
filters = @.prepareFilters()
console.log filters
promise = @rs.issues.list(@scope.projectId, filters).then (data) =>
@scope.issues = data.models
@ -175,6 +185,15 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
.then(=> @.loadFilters())
.then(=> @.loadIssues())
# Functions used from templates
addNewIssue: ->
console.log "Kakita"
@rootscope.$broadcast("issueform:new")
addIssuesInBulk: ->
@rootscope.$broadcast("issueform:bulk")
module.controller("IssuesController", IssuesController)
#############################################################################

View File

@ -18,8 +18,8 @@ block content
// Paginator is rended using js.
div.paginator.issues-paginator
div.hidden.lightbox.lightbox_add-issue
div.hidden.lightbox.lightbox_add-issue(tg-lb-create-issue)
include views/modules/lightbox_add-issue
div.hidden.lightbox.lightbox_add-bulk
include views/modules/lightbox_add-bulk
div.hidden.lightbox.lightbox_add-bulk(tg-lb-create-bulk-issues)
include views/modules/lightbox_add-bulk

View File

@ -3,32 +3,24 @@ a.close(href="", title="close")
form
h2.title Add Issue
fieldset
input(type="text", placeholder="Issue description")
input(type="text", ng-model="issue.subject", placeholder="Issue description",
data-required="true", data-maxlength="500")
div.fieldset-row
// fieldset
// select.type
// option(value="Type") Type
fieldset
select.type
option(value="Type") Type
select.priority(ng-model="issue.priority", ng-options="p.id as p.name for p in priorityList")
fieldset
select.priority
option(value="priority") Priority
fieldset
select.severity
option(value="severity") Severity
//-
div.fieldset-row
fieldset
select.assigned-to
option(value="assigned-to") Assigned to
fieldset
select.status
option(value="status") Status
fieldset
input(type="checkbox", id="is-blocked")
label(for="is-blocked") is blocked?
select.severity(ng-model="issue.severity", ng-options="s.id as s.name for s in severityList")
fieldset
input(type="text", placeholder="Add tags")
input(type="text", placeholder="Tags", tg-tags, ng-model="issue.tags")
fieldset
textarea.description(placeholder="description")
include lightbox-attachments
textarea.description(placeholder="description", ng-model="issue.description")
// include lightbox-attachments
input(type="submit", style="display:none")
a.button.button-green(href="", title="Save")
span Create

View File

@ -11,8 +11,8 @@ section.list-filters
// | SHOW GRAPH
div.new-issue
a.button.button-green(href="")
a.button.button-green(href="", ng-click="ctrl.addNewIssue()")
span.text
| + NEW ISSUE
a.button-bulk(href="")
a.button-bulk(href="", ng-click="ctrl.addIssuesInBulk()")
span.icon.icon-bulk