diff --git a/app/assets/javascripts/angular-new/issues/issue_controller.js.coffee b/app/assets/javascripts/angular-new/issues/issue_controller.js.coffee index 081859dbb..20d0dd2cc 100644 --- a/app/assets/javascripts/angular-new/issues/issue_controller.js.coffee +++ b/app/assets/javascripts/angular-new/issues/issue_controller.js.coffee @@ -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'] diff --git a/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee b/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee index 9d4097b00..56ba76029 100644 --- a/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee +++ b/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee @@ -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) -> diff --git a/app/assets/javascripts/angular-new/labels/label.js.coffee b/app/assets/javascripts/angular-new/labels/label.js.coffee index a1128149c..2352182cb 100644 --- a/app/assets/javascripts/angular-new/labels/label.js.coffee +++ b/app/assets/javascripts/angular-new/labels/label.js.coffee @@ -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") diff --git a/app/assets/javascripts/angular-new/labels/labels_controller.js.coffee.erb b/app/assets/javascripts/angular-new/labels/labels_controller.js.coffee.erb index 59af62d8f..89018de5b 100644 --- a/app/assets/javascripts/angular-new/labels/labels_controller.js.coffee.erb +++ b/app/assets/javascripts/angular-new/labels/labels_controller.js.coffee.erb @@ -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 diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 65ca14960..b66a7ecf7 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -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 diff --git a/app/models/issue.rb b/app/models/issue.rb index a3c76f8c7..fd0e8e176 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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) } diff --git a/app/views/projects/comments/_body.html.slim b/app/views/projects/comments/_body.html.slim index 7e39547c9..8f031e306 100644 --- a/app/views/projects/comments/_body.html.slim +++ b/app/views/projects/comments/_body.html.slim @@ -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()' ] diff --git a/app/views/projects/issues/_filter_labels.html.slim b/app/views/projects/issues/_filter_labels.html.slim index 0a218f33f..3e4b5c8ac 100644 --- a/app/views/projects/issues/_filter_labels.html.slim +++ b/app/views/projects/issues/_filter_labels.html.slim @@ -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 = '#' diff --git a/app/views/projects/issues/_form.html.slim b/app/views/projects/issues/_form.html.slim index 9eff51597..8ea4c6458 100644 --- a/app/views/projects/issues/_form.html.slim +++ b/app/views/projects/issues/_form.html.slim @@ -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) diff --git a/app/views/projects/issues/_manage_labels.html.slim b/app/views/projects/issues/_manage_labels.html.slim index 9049fd64d..38fec6489 100644 --- a/app/views/projects/issues/_manage_labels.html.slim +++ b/app/views/projects/issues/_manage_labels.html.slim @@ -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') diff --git a/app/views/projects/issues/_select_labels.html.slim b/app/views/projects/issues/_select_labels.html.slim new file mode 100644 index 000000000..07bb543d9 --- /dev/null +++ b/app/views/projects/issues/_select_labels.html.slim @@ -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' ]   + | {{label.name}} + input.hidden[ name = 'issue[labelings_attributes][][label_id]' + ng-model = 'label.selected_id' + ng-value = 'label.selected_id' ] diff --git a/app/views/projects/issues/new.html.slim b/app/views/projects/issues/new.html.slim index bda82f1c0..f5c7a7460 100644 --- a/app/views/projects/issues/new.html.slim +++ b/app/views/projects/issues/new.html.slim @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 8416506b8..76bc65c5a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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