Skip to content

Commit

Permalink
Adds labels on interventions. Related to #1041.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice TEXIER committed Sep 11, 2016
1 parent abfff45 commit 54bd262
Show file tree
Hide file tree
Showing 42 changed files with 248 additions and 37 deletions.
8 changes: 7 additions & 1 deletion app/controllers/backend/interventions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def self.list_conditions
code << " c << params[:product_id].to_i\n"
code << "end\n"

# Label
code << "if params[:label_id].to_i > 0\n"
code << " c[0] << ' AND #{Intervention.table_name}.id IN (SELECT intervention_id FROM intervention_labellings WHERE label_id IN (?))'\n"
code << " c << params[:label_id].to_i\n"
code << "end\n"

# ActivityProduction || Activity
code << "if params[:production_id].to_i > 0\n"
code << " c[0] << ' AND #{Intervention.table_name}.id IN (SELECT intervention_id FROM intervention_parameters WHERE type = \\'InterventionTarget\\' AND product_id IN (SELECT target_id FROM target_distributions WHERE activity_production_id = ?))'\n"
Expand Down Expand Up @@ -123,7 +129,7 @@ def self.list_conditions
# Show one intervention with params_id
def show
return unless @intervention = find_and_check
t3e @intervention, procedure_name: @intervention.name
t3e @intervention, procedure_name: @intervention.procedure.human_name
respond_with(@intervention, methods: [:cost, :earn, :status, :name, :duration, :human_working_zone_area, :human_actions_names],
include: [
{ leaves_parameters: {
Expand Down
31 changes: 31 additions & 0 deletions app/controllers/backend/labels_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# == License
# Ekylibre - Simple agricultural ERP
# Copyright (C) 2015 Brice Texier, David Joulin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

module Backend
class LabelsController < Backend::BaseController
manage_restfully

unroll

list do |t|
t.action :edit
t.action :destroy
t.column :name, url: true
end
end
end
11 changes: 11 additions & 0 deletions app/helpers/backend/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ def resource_info(name, options = {}, &block)
end
end


def labels_info(labels)
if labels.any?
content_tag(:div, class: 'info-labels') do
labels.map do |label|
content_tag(:div, label.name, class: 'label', style: "background-color: #{label.color}; color: #{contrasted_color(label.color)}") + ' '.html_safe
end.join.html_safe
end
end
end

def info(label, value, options = {}, &_block)
css_class = "#{options.delete(:level) || :med}-info"
options[:class] = if options[:class]
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/charts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ module ChartsHelper
hash
end.freeze

def lightness(color)
r = color[1..2].to_i(16)
g = color[3..4].to_i(16)
b = color[5..6].to_i(16)
0.299 * r + 0.587 * g + 0.114 * b
end

def contrasted_color(color)
if lightness(color) > 160
'#000000'
else
'#FFFFFF'
end
end

def ligthen(color, rate)
r = color[1..2].to_i(16)
g = color[3..4].to_i(16)
Expand Down
8 changes: 8 additions & 0 deletions app/models/concerns/labellable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Labellable
extend ActiveSupport::Concern

included do
belongs_to :label
delegate :color, :name, to: :label
end
end
1 change: 1 addition & 0 deletions app/models/intervention.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Intervention < Ekylibre::Record::Base

acts_as_numbered
accepts_nested_attributes_for :group_parameters, :doers, :inputs, :outputs, :targets, :tools, :working_periods, allow_destroy: true
accepts_nested_attributes_for :labellings, allow_destroy: true

scope :between, lambda { |started_at, stopped_at|
where(started_at: started_at..stopped_at)
Expand Down
2 changes: 1 addition & 1 deletion app/models/intervention_labelling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
# updater_id :integer
#
class InterventionLabelling < Ekylibre::Record::Base
include Labellable
belongs_to :intervention
belongs_to :label
# [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates :intervention, :label, presence: true
# ]VALIDATORS]
Expand Down
2 changes: 1 addition & 1 deletion app/models/product_labelling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
# updater_id :integer
#
class ProductLabelling < Ekylibre::Record::Base
include Labellable
belongs_to :product
belongs_to :label
# [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates :label, :product, presence: true
# ]VALIDATORS]
Expand Down
7 changes: 7 additions & 0 deletions app/themes/tekyla/stylesheets/main.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "bootstrap/labels";

i.icon {
@include is-icon;
}
Expand Down Expand Up @@ -825,6 +827,11 @@ form.search {
}
}

.info-labels {
padding: $default-gap 2 * $default-gap;
font-size: $fs-large;
line-height: $lh-large;
}

.info {
@include ellipsis;
Expand Down
2 changes: 2 additions & 0 deletions app/views/backend/interventions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
- started_at ||= stopped_at - 1.hour
- f.object.working_periods.new(started_at: started_at, stopped_at: stopped_at)
= f.nested_association(:working_periods, minimum: 1, locals: {namespace: 'working_periods'})
#labellings
= f.nested_association(:labellings)

= field_set :parameters do
- procedure.each_parameter do |parameter|
Expand Down
3 changes: 3 additions & 0 deletions app/views/backend/interventions/_labelling_fields.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.nested-fields
= link_to_remove_nested_association('label', f)
= f.referenced_association :label
4 changes: 4 additions & 0 deletions app/views/backend/interventions/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
%label= ActivityProduction.human_attribute_name(:support)
= select_tag(:product_id, options_for_select([[]] + targets.select(:product_id).distinct.collect{|u| [u.product.work_name, u.product_id]}, params[:product_id]))
-#= select_tag(:support_id, options_for_select([[]] + productions.joins(:support).reorder('products.work_number').collect{|u| [u.work_name, u.id]}, params[:support_id]))
- if InterventionLabelling.any?
- k.helper do
%label= Label.model_name.human
= select_tag(:label_id, options_for_select([[]] + Label.where(id: InterventionLabelling.select(:label_id).uniq).map{ |l| [l.name, l.id] }, params[:label_id].to_i))

- main_toolbar do |t|
= t.new(nature: :request, label: :add_intervention_request.tl)
Expand Down
1 change: 1 addition & 0 deletions app/views/backend/interventions/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
.info
%span.title= Intervention.human_attribute_name(:trouble_encountered)
%span.value= resource.trouble_description
= labels_info(resource.labels)

- if resource.request?
- c.cobble(:record_interventions, title: :x_interventions.tl(count: resource.record_interventions.count)) do
Expand Down
3 changes: 3 additions & 0 deletions app/views/backend/labels/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= field_set do
= f.input :name
= f.input :color, as: :color
4 changes: 4 additions & 0 deletions app/views/backend/labels/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= main_toolbar do |t|
= t.new

= main_list
6 changes: 6 additions & 0 deletions app/views/backend/labels/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
= main_toolbar do |t|
= t.edit resource

= main_informations do
= attributes_list do |l|
- l.attribute :name
4 changes: 0 additions & 4 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 0 additions & 4 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError
end
require_relative '../config/boot'
require 'rake'
Rake.application.run
6 changes: 6 additions & 0 deletions config/locales/arb/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ arb:
new: "انشاء دفتر يومي جديد"
reopen: "فتح %{name}"
show: "الدفتر اليومي : %{name} (%{code})"
backend/labels:
# edit: "Edit label: %{name}"
index: "تسميات"
new: "تسمية جديدة"
# show: "Label: %{name}"
backend/land_parcels:
edit: "تعديل النظام : %{name}"
index: "انظمة"
Expand Down Expand Up @@ -935,6 +940,7 @@ arb:
add_intervention_record: "اضافة التسجيلة تدخل"
add_intervention_request: "إضافة طلب تدخل"
add_item: "إضافة البند"
add_labelling: "إضافة تسمية"
add_line: "إضافة خط"
add_linestring: "إضافة تنسيقي"
add_mail: "إضافة عنوان البريدي"
Expand Down
7 changes: 5 additions & 2 deletions config/locales/arb/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ arb:
intervention_doer: "التدخل الفاعل"
intervention_group_parameter: "المعلمة مجموعة التدخل"
intervention_input: "المدخلات تدخل"
intervention_labelling: "تدخل الوسم"
intervention_output: "الناتج تدخل"
intervention_parameter: "معلمة تدخل"
intervention_parameter_reading: "مهمة القراءة المنتج"
Expand All @@ -850,6 +851,7 @@ arb:
journal_entry: "المدخلات"
journal_entry_item: "مجلة البند دخول"
journal_record: "سجل المحاسبة" #?
label: "ملصق"
land_parcel: "الكتلة"
listing: "الاستخراج"
listing_node: "عقدة الاستخراج"
Expand Down Expand Up @@ -890,6 +892,7 @@ arb:
product_component: "عنصر الانتاج" #?
product_enjoyment: "تمتع المنتج"
product_group: "مجموعة المنتجات"
product_labelling: "وسم المنتجات"
product_link: "رابط المنتج"
product_linkage: "الربط المنتج"
product_localization: "توطين المنتج"
Expand Down Expand Up @@ -1565,8 +1568,8 @@ arb:
journals: "الدفاتر اليومية" #?
key: "المفتاح"
label: "الملصق"
# labellings: "Labellings"
# labels: "Labels"
labellings: "وضع العلامات"
labels: "تسميات"
land_parcel_number: "عدد قطعة أرض"
land_parcels: "الكتل"
language: "اللغة"
Expand Down
6 changes: 6 additions & 0 deletions config/locales/cmn/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ cmn:
new: "新期刊"
# reopen: "Reopen journal: %{name}"
# show: "Journal: %{name} (%{code})"
backend/labels:
# edit: "Edit label: %{name}"
index: "标签"
new: "新标签"
# show: "Label: %{name}"
backend/land_parcels:
# edit: "Edit land parcel: %{name}"
index: "地块"
Expand Down Expand Up @@ -666,6 +671,7 @@ cmn:
add_intervention_record: "加入干预纪录"
add_intervention_request: "加入干预的请求"
add_item: "新增项目"
add_labelling: "添加标签"
add_line: "添加行"
add_linestring: "添加线串"
add_mail: "添加邮政ADRESS"
Expand Down
5 changes: 4 additions & 1 deletion config/locales/cmn/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ cmn:
intervention_doer: "干预实干家"
intervention_group_parameter: "干预组参数"
intervention_input: "输入干预"
intervention_labelling: "干预的标签"
intervention_output: "干预输出"
intervention_parameter: "干预参数"
intervention_parameter_reading: "产品阅读任务"
Expand All @@ -231,6 +232,7 @@ cmn:
journal: "日志"
journal_entry: "日记条目"
journal_entry_item: "日记条目项目"
label: "标签"
land_parcel: "地块"
listing: "清单"
listing_node: "清单节点"
Expand Down Expand Up @@ -259,6 +261,7 @@ cmn:
product: "产品"
product_enjoyment: "产品享受"
product_group: "产品组"
product_labelling: "产品标签"
product_link: "产品链接"
product_linkage: "产品链接"
product_localization: "产品本地化"
Expand Down Expand Up @@ -760,7 +763,7 @@ cmn:
key: ""
label: "标签"
# labellings: "Labellings"
# labels: "Labels"
labels: "标签"
land_parcel_number: "地块编号"
land_parcels: "地块"
language: "语言"
Expand Down
6 changes: 6 additions & 0 deletions config/locales/deu/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ deu:
new: "neue Zeitschrift"
# reopen: "Reopen journal: %{name}"
# show: "Journal: %{name} (%{code})"
backend/labels:
# edit: "Edit label: %{name}"
# index: "Labels"
new: "Neues Label"
# show: "Label: %{name}"
backend/land_parcels:
# edit: "Edit land parcel: %{name}"
index: "Parzellen"
Expand Down Expand Up @@ -666,6 +671,7 @@ deu:
add_intervention_record: "In Intervention Rekord"
add_intervention_request: "In Serviceanfrage"
add_item: "Artikel hinzufügen"
add_labelling: "Label hinzufügen"
add_line: "In Zeile"
add_linestring: "In Linienfolge"
add_mail: "In Postanschrift"
Expand Down
5 changes: 4 additions & 1 deletion config/locales/deu/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ deu:
intervention_doer: "Intervention Macher"
intervention_group_parameter: "Interventionsgruppe Parameter"
intervention_input: "Intervention Eingangs"
intervention_labelling: "Intervention Kennzeichnung"
intervention_output: "Intervention Ausgangs"
intervention_parameter: "Intervention Parameter"
intervention_parameter_reading: "Produktleseaufgabe"
Expand All @@ -231,6 +232,7 @@ deu:
journal: "Zeitschrift"
journal_entry: "Tagebucheintrag"
journal_entry_item: "Journaleintrag Artikel"
label: "Etikette"
land_parcel: "Parzelle"
listing: "Auflistung"
listing_node: "Listing Knoten"
Expand Down Expand Up @@ -259,6 +261,7 @@ deu:
product: "Produkt"
product_enjoyment: "Produkt-Genuss"
product_group: "Produktgruppe"
product_labelling: "Produktkennzeichnung"
product_link: "Link zum Produkt"
product_linkage: "Produktverknüpfung"
product_localization: "Produktlokalisierung"
Expand Down Expand Up @@ -759,7 +762,7 @@ deu:
journal_entry_items: "Journaleintrag Artikel"
key: "Taste"
label: "Etikette"
# labellings: "Labellings"
labellings: "Etikettierungen"
# labels: "Labels"
land_parcel_number: "Land Paketnummer"
land_parcels: "Parzellen"
Expand Down
1 change: 1 addition & 0 deletions config/locales/eng/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ eng:
journal_draft: "Journal draft"
journal_entries: "Journal entries"
journals: "Journals"
# labels: "Labels"
land_parcels: "Land parcels"
listings: "Listings"
loans: "Loans"
Expand Down
Loading

0 comments on commit 54bd262

Please sign in to comment.