From 6ac26a3cb6feabf09aefc4e23855c393d50cf08a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 30 Jul 2014 13:27:29 +0300 Subject: [PATCH] Label views: index, new, edit Signed-off-by: Dmitriy Zaporozhets --- app/assets/stylesheets/sections/labels.scss | 17 ++++++++ app/helpers/labels_helper.rb | 13 ++++++ app/views/projects/labels/_form.html.haml | 48 +++++++++++++++++++++ app/views/projects/labels/_label.html.haml | 2 + app/views/projects/labels/edit.html.haml | 8 ++++ app/views/projects/labels/index.html.haml | 12 ++++-- app/views/projects/labels/new.html.haml | 6 +++ 7 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 app/assets/stylesheets/sections/labels.scss create mode 100644 app/views/projects/labels/_form.html.haml create mode 100644 app/views/projects/labels/edit.html.haml create mode 100644 app/views/projects/labels/new.html.haml diff --git a/app/assets/stylesheets/sections/labels.scss b/app/assets/stylesheets/sections/labels.scss new file mode 100644 index 00000000000..96f32d78f5c --- /dev/null +++ b/app/assets/stylesheets/sections/labels.scss @@ -0,0 +1,17 @@ +.suggest-colors { + margin-top: 5px; + a { + @include border-radius(4px); + width: 30px; + height: 30px; + display: inline-block; + margin-right: 10px; + } +} + +.manage-labels-list { + .label { + padding: 9px; + font-size: 14px; + } +} diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index fce0ed6c5d6..b4082d625f3 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -17,4 +17,17 @@ module LabelsHelper label.name end end + + def suggested_colors + [ + '#d9534f', + '#f0ad4e', + '#428bca', + '#5cb85c', + '#34495e', + '#7f8c8d', + '#8e44ad', + '#FFECDB' + ] + end end diff --git a/app/views/projects/labels/_form.html.haml b/app/views/projects/labels/_form.html.haml new file mode 100644 index 00000000000..1720a0a915d --- /dev/null +++ b/app/views/projects/labels/_form.html.haml @@ -0,0 +1,48 @@ += form_for [@project, @label], html: { class: 'form-horizontal label-form' } do |f| + -if @label.errors.any? + .row + .col-sm-10.col-sm-offset-2 + .bs-callout.bs-callout-danger + - @label.errors.full_messages.each do |msg| + %span= msg + %br + + .form-group + = f.label :title, class: 'control-label' + .col-sm-10 + = f.text_field :title, class: "form-control", required: true + .form-group + = f.label :color, "Background Color", class: 'control-label' + .col-sm-10 + .input-group + .input-group-addon.label-color-preview   + = f.text_field :color, placeholder: "#AA33EE", class: "form-control" + .help-block + 6 character hex values starting with a # sign. + %br + Or you can choose one of suggested colors below + + .suggest-colors + - suggested_colors.each do |color| + = link_to '#', style: "background-color: #{color}", data: { color: color } do +   + + .form-actions + = f.submit 'Save', class: 'btn btn-save' + + +:coffeescript + updateColorPreview = -> + previewColor = $('input#label_color').val() + $('div.label-color-preview').css('background-color', previewColor) + + $('.suggest-colors a').on 'click', (e) -> + color = $(this).data("color") + $('input#label_color').val(color) + updateColorPreview() + e.preventDefault() + + $('input#label_color').on 'input', -> + updateColorPreview() + + updateColorPreview() diff --git a/app/views/projects/labels/_label.html.haml b/app/views/projects/labels/_label.html.haml index cf736788c9a..59bf31314e7 100644 --- a/app/views/projects/labels/_label.html.haml +++ b/app/views/projects/labels/_label.html.haml @@ -1,2 +1,4 @@ %li = render_colored_label(label) + .pull-right + = link_to 'Edit', edit_project_label_path(@project, label), class: 'btn' diff --git a/app/views/projects/labels/edit.html.haml b/app/views/projects/labels/edit.html.haml new file mode 100644 index 00000000000..52435c5d892 --- /dev/null +++ b/app/views/projects/labels/edit.html.haml @@ -0,0 +1,8 @@ +%h3 + Edit label + %span.light #{@label.name} +.back-link + = link_to project_labels_path(@project) do + ← To labels list +%hr += render 'form' diff --git a/app/views/projects/labels/index.html.haml b/app/views/projects/labels/index.html.haml index 329cf9ceba8..f7d535e52f5 100644 --- a/app/views/projects/labels/index.html.haml +++ b/app/views/projects/labels/index.html.haml @@ -1,9 +1,15 @@ = render "projects/issues/head" +- if can? current_user, :admin_label, @project + = link_to new_project_label_path(@project), class: "pull-right btn btn-new" do + New label +%h3.page-title + Labels +%hr + - if @labels.present? - %ul.bordered-list.labels-table - - @labels.each do |label| - = render 'label', label: label + %ul.bordered-list.manage-labels-list + = render @labels - else .light-well diff --git a/app/views/projects/labels/new.html.haml b/app/views/projects/labels/new.html.haml new file mode 100644 index 00000000000..850da0b192b --- /dev/null +++ b/app/views/projects/labels/new.html.haml @@ -0,0 +1,6 @@ +%h3 New label +.back-link + = link_to project_labels_path(@project) do + ← To labels list +%hr += render 'form'