[#369] new issue page: labels; small fixes

This commit is contained in:
Alexander Machehin 2014-11-27 23:55:03 +05:00
parent 65498ca47b
commit 5a2c4896ad
13 changed files with 99 additions and 43 deletions

View File

@ -1,4 +1,19 @@
IssueController = (dataservice, $http, Issue, $rootScope, Preview) ->
IssueController = (dataservice, $http, Issue, $rootScope, Preview, Label) ->
getLabels = ->
promise = Label.get_labels(vm.project)
promise.then (response) ->
old_labels = vm.labels
vm.labels = response.data
_.each(vm.labels, (l) ->
_.each(old_labels, (ol) ->
if l.id is ol.id
l.selected = ol.selected
l.style = ol.style
l.selected_id = ol.selected_id
)
)
true
vm = this
@ -22,6 +37,18 @@ IssueController = (dataservice, $http, Issue, $rootScope, Preview) ->
vm.processing = false
false
vm.toggleLabel = (label) ->
label.selected = !label.selected
if label.selected
label.style = label.default_style
label.selected_id = label.id
else
label.selected_id = null
label.style = {}
$rootScope.$on "updateLabels", (event, args) ->
getLabels()
init = (dataservice) ->
vm.project = dataservice.project
vm.labels = dataservice.labels
@ -34,4 +61,4 @@ angular
.module("RosaABF")
.controller "IssueController", IssueController
IssueController.$inject = ['IssueInitializer', '$http', 'Issue', '$rootScope', 'Preview']
IssueController.$inject = ['IssueInitializer', '$http', 'Issue', '$rootScope', 'Preview', 'Label']

View File

@ -73,7 +73,7 @@ IssuesController = (dataservice, $http, $location, Issue, $rootScope) ->
label.style = {}
getIssues()
$rootScope.$on "updateIssues", (event, args) ->
$rootScope.$on "updateLabels", (event, args) ->
getIssues()
init = (dataservice) ->

View File

@ -31,7 +31,11 @@ labelService = ($http) ->
remove: (project, label) ->
path = Routes.project_issues_delete_label_path(project, label.id)
$http.post(path)
}
get_labels: (project) ->
path = Routes.project_labels_path(project)
$http.get(path)
}
angular
.module("RosaABF")

View File

@ -41,7 +41,7 @@ LabelsController = (dataservice, $http, Label, $rootScope, $scope) ->
promise.success( (data) ->
vm.labels = data
vm.errors = []
$rootScope.$broadcast('updateIssues')
$rootScope.$broadcast('updateLabels')
).error( (data) ->
vm.errors = data
)
@ -52,24 +52,24 @@ LabelsController = (dataservice, $http, Label, $rootScope, $scope) ->
return false unless confirmMessage()
promise = Label.remove(vm.project, l)
promise.success (data) ->
$rootScope.$broadcast('updateIssues')
$rootScope.$broadcast('updateLabels')
false
init = (dataservice) ->
vm.project = dataservice.project
vm.labels = dataservice.labels
vm.vis_manage_block = false
vm.project = dataservice.project
vm.labels = dataservice.labels
vm.is_collapsed_manage_block = true
vm.default_colors = Label.default_colors
vm.label = {
id: null
name: null
color: vm.default_colors[0]
}
vm.is_new_label = true
vm.processing = false
vm.default_colors = Label.default_colors
vm.label = {
id: null
name: null
color: vm.default_colors[0]
}
vm.is_new_label = true
vm.processing = false
init(dataservice)
true

View File

@ -69,6 +69,10 @@ class Projects::IssuesController < Projects::BaseController
index
end
def labels
render partial: 'projects/issues/labels.json', locals: {project: @project}, layout: false
end
def new
end
@ -145,10 +149,12 @@ class Projects::IssuesController < Projects::BaseController
end
def destroy_label
if @label.destroy
format.json { render partial: 'labels', locals: {project: @project} }
else
render json: @label.errors.full_messages, status: 422
respond_to do |format|
if @label.destroy
format.json { render partial: 'labels', locals: {project: @project} }
else
format.json { render json: @label.errors.full_messages, status: 422 }
end
end
end

View File

@ -46,7 +46,8 @@ class Issue < ActiveRecord::Base
before_update :update_statistic
attr_accessible :labelings_attributes, :title, :body, :assignee_id
accepts_nested_attributes_for :labelings, allow_destroy: true
accepts_nested_attributes_for :labelings,
reject_if: lambda {|attributes| attributes['label_id'].blank?}
scope :opened, -> { where(status: [STATUS_OPEN, STATUS_REOPEN]) }
scope :closed, -> { where(status: STATUS_CLOSED) }

View File

@ -1,10 +1,8 @@
tabset
tab heading = t('layout.edit')
.offset10
= f.input_field :body,
class: 'form-control',
rows: 10,
'ng-model' => 'issueCtrl.body'
= f.input :body, label: false,
input_html: { rows: 10 }
tab[ heading = t('layout.preview')
select = 'issueCtrl.previewBody()' ]

View File

@ -1,3 +1,4 @@
h4=t('layout.issues.labels')
ul.nav.nav-pills.nav-stacked
li[ role = 'presentation' ng-repeat = 'label in issuesCtrl.labels' ]
a[ href = '#'

View File

@ -1,4 +1,7 @@
=render 'title_body', f: f, id: 'new'
= submit_tag t(@issue.new_record? ? 'layout.create' : 'layout.update'),
class: 'btn btn-primary',
data: {'disable-with' => t('layout.processing')}
/
- if can?(:write, @project)

View File

@ -1,9 +1,9 @@
div ng-controller = 'LabelsController as labelsCtrl' ng-cloak = true
hr
button.btn.btn-primary ng-click = 'labelsCtrl.vis_manage_block = !labelsCtrl.vis_manage_block'
=t('layout.issues.label_manage')
button.btn.btn-primary[ ng-click = 'labelsCtrl.is_collapsed_manage_block = !labelsCtrl.is_collapsed_manage_block'
type = 'button' ]= t('layout.issues.label_manage')
.offset5 ng-show = 'labelsCtrl.vis_manage_block'
.offset5 collapse = 'labelsCtrl.is_collapsed_manage_block'
.row ng-repeat = "label in labelsCtrl.labels"
.col-md-10
.update-label.lpadding-5[ ng-style = 'label.default_style'
@ -47,7 +47,7 @@ div ng-controller = 'LabelsController as labelsCtrl' ng-cloak = true
p.text-warning[ ng-repeat = 'error in labelsCtrl.errors' ] {{ error }}
button.btn.btn-primary[ type = 'submit'
button.btn.btn-primary[ type = 'button'
ng-click = 'labelsCtrl.saveLabel()'
ng-disabled = 'labelsCtrl.processing' ]
div[ ng-show = 'labelsCtrl.processing' ]= t('layout.processing')

View File

@ -0,0 +1,12 @@
h4=t('layout.issues.labels')
ul.nav.nav-pills.nav-stacked
li[ role = 'presentation' ng-repeat = 'label in issueCtrl.labels' ]
a[ href = '#'
ng-click = 'issueCtrl.toggleLabel(label)'
ng-style = 'label.style' ]
.label-flag[ ng-style = 'label.default_style'
ng-show = '!label.selected' ] &nbsp;
| {{label.name}}
input.hidden[ name = 'issue[labelings_attributes][][label_id]'
ng-model = 'label.selected_id'
ng-value = 'label.selected_id' ]

View File

@ -1,17 +1,20 @@
-set_meta_tags title: [title_object(@project), t('layout.issues.create_header')]
-render 'submenu'
-render 'manage_sidebar'
.container ng-controller = 'IssueController as issueCtrl' ng-cloak = true
.row
.col-md-3.col-sm-4.offset20
= render 'manage_labels', project: @project
.col-md-9.col-sm-8.offset20
= simple_form_for @issue do |f|
h3= title t('layout.issues.create_header')
= render 'form', f: f
= simple_form_for @issue, url: project_issues_path(@project) do |f|
.row
.col-md-3.col-sm-4.offset20
- if can?(:write, @project)
= render 'projects/comments/markdown_help'
== render 'select_labels'
== render 'manage_labels'
.col-md-9.col-sm-8.offset20
h3= title t('layout.issues.create_header')
== render 'form', f: f
== render 'projects/comments/markdown_help'
- content_for :additional_scripts do
= render 'init_service.js.erb'
== render 'init_service.js.erb'

View File

@ -327,10 +327,11 @@ Rosa::Application.routes.draw do
get :search_collaborators
end
end
get 'pull_requests' => 'issues#pull_requests', as: :pull_requests
post "/labels/:label_id" => "issues#destroy_label", as: :issues_delete_label
post "/labels/:label_id/update" => "issues#update_label", as: :issues_update_label
get 'pull_requests' => 'issues#pull_requests', as: :pull_requests
get 'labels' => 'issues#labels', as: :labels
post 'labels/:label_id' => 'issues#destroy_label', as: :issues_delete_label
post 'labels/:label_id/update' => 'issues#update_label', as: :issues_update_label
resources :build_lists, only: [:index, :new, :create] do
get :list, on: :collection