From da2ce8e1b4fc052549eaaf49b7411c2c21ec94c7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 28 Sep 2016 14:12:28 +0200 Subject: [PATCH] Streamline of attribute selection for overviews. --- .../checkboxTicketAttributes.coffee | 32 +++++++ .../_ui_element/selectTicketAttributes.coffee | 31 +++++++ .../app/controllers/ticket_overview.coffee | 38 ++------ .../javascripts/app/models/overview.coffee | 89 +------------------ 4 files changed, 72 insertions(+), 118 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/_ui_element/checkboxTicketAttributes.coffee create mode 100644 app/assets/javascripts/app/controllers/_ui_element/selectTicketAttributes.coffee diff --git a/app/assets/javascripts/app/controllers/_ui_element/checkboxTicketAttributes.coffee b/app/assets/javascripts/app/controllers/_ui_element/checkboxTicketAttributes.coffee new file mode 100644 index 000000000..608a2f0fc --- /dev/null +++ b/app/assets/javascripts/app/controllers/_ui_element/checkboxTicketAttributes.coffee @@ -0,0 +1,32 @@ +# coffeelint: disable=camel_case_classes +class App.UiElement.checkboxTicketAttributes extends App.UiElement.ApplicationUiElement + @render: (attribute, params) -> + + configureAttributes = App.Ticket.configure_attributes + for row, localAttribute of App.Ticket.attributesGet() + configureAttributes.push localAttribute + attributeOptionsArray = [] + attributeOptions = {} + for row in configureAttributes + + # ignore passwords + if row.type isnt 'password' && row.type isnt 'tag' && row.name isnt 'tags' + nameTmp = row.name + + # get correct data name + if row.name.substr(row.name.length-4,4) is '_ids' + nameTmp = row.name.substr(0, row.name.length-4) + else if row.name.substr(row.name.length-3,3) is '_id' + nameTmp = row.name.substr(0, row.name.length-3) + + if !attributeOptions[ nameTmp ] + attributeOptions[ nameTmp ] = row.display + attributeOptionsArray.push( + { + value: nameTmp + name: row.display + } + ) + attribute.item_class = 'checkbox' + attribute.options = attributeOptions + App.UiElement.checkbox.render(attribute, params) diff --git a/app/assets/javascripts/app/controllers/_ui_element/selectTicketAttributes.coffee b/app/assets/javascripts/app/controllers/_ui_element/selectTicketAttributes.coffee new file mode 100644 index 000000000..47b3284c8 --- /dev/null +++ b/app/assets/javascripts/app/controllers/_ui_element/selectTicketAttributes.coffee @@ -0,0 +1,31 @@ +# coffeelint: disable=camel_case_classes +class App.UiElement.selectTicketAttributes extends App.UiElement.ApplicationUiElement + @render: (attribute, params) -> + + configureAttributes = App.Ticket.configure_attributes + for row, localAttribute of App.Ticket.attributesGet() + configureAttributes.push localAttribute + attributeOptionsArray = [] + attributeOptions = {} + for row in configureAttributes + + # ignore passwords + if row.type isnt 'password' && row.type isnt 'tag' && row.name isnt 'tags' + nameTmp = row.name + + # get correct data name + if row.name.substr(row.name.length-4,4) is '_ids' + nameTmp = row.name.substr(0, row.name.length-4) + else if row.name.substr(row.name.length-3,3) is '_id' + nameTmp = row.name.substr(0, row.name.length-3) + + if !attributeOptions[ nameTmp ] + attributeOptions[ nameTmp ] = row.display + attributeOptionsArray.push( + { + value: nameTmp + name: row.display + } + ) + attribute.options = attributeOptions + App.UiElement.select.render(attribute, params) diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index ed9aba9de..33c7c93e0 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.coffee @@ -764,50 +764,24 @@ class App.OverviewSettings extends App.ControllerModal 25: '25' }, }) - attributeOptions = {} - attributeOptionsArray = [] - configure_attributes = App.Ticket.configure_attributes - for row, attribute of App.Ticket.attributesGet() - configure_attributes.push attribute - for row in configure_attributes - # ignore passwords - if row.type isnt 'password' - name = row.name - - # get correct data name - if row.name.substr(row.name.length-4,4) is '_ids' - name = row.name.substr(0, row.name.length-4) - else if row.name.substr(row.name.length-3,3) is '_id' - name = row.name.substr(0, row.name.length-3) - - if !attributeOptions[ name ] - attributeOptions[ name ] = row.display - attributeOptionsArray.push( - { - value: name - name: row.display - } - ) @configure_attributes_article.push({ name: "view::#{@view_mode}" display: 'Attributes' - tag: 'checkbox' + tag: 'checkboxTicketAttributes' default: @overview.view[@view_mode] null: false translate: true - sortBy: null - options: attributeOptionsArray + sortBy: null }, { name: 'order::by' display: 'Order' - tag: 'select' + tag: 'selectTicketAttributes' default: @overview.order.by null: false translate: true - sortBy: null - options: attributeOptionsArray + sortBy: null }, { name: 'order::direction' @@ -817,8 +791,8 @@ class App.OverviewSettings extends App.ControllerModal null: false translate: true options: - ASC: 'up' - DESC: 'down' + ASC: 'up' + DESC: 'down' }, { name: 'group_by' diff --git a/app/assets/javascripts/app/models/overview.coffee b/app/assets/javascripts/app/models/overview.coffee index 7e94633a2..029470430 100644 --- a/app/assets/javascripts/app/models/overview.coffee +++ b/app/assets/javascripts/app/models/overview.coffee @@ -13,99 +13,18 @@ class App.Overview extends App.Model { name: 'view::s' display: 'Attributes' - tag: 'checkbox' + tag: 'checkboxTicketAttributes' default: ['number', 'title', 'state', 'created_at'] null: false translate: true - options: [ - { - value: 'number' - name: 'Number' - }, - { - value: 'title' - name: 'Title' - }, - { - value: 'customer' - name: 'Customer' - }, - { - value: 'state' - name: 'State' - }, - { - value: 'priority' - name: 'Priority' - }, - { - value: 'group' - name: 'Group' - }, - { - value: 'owner' - name: 'Owner' - }, - { - value: 'last_contact_at' - name: 'Last contact' - }, - { - value: 'last_contact_agent_at' - name: 'Last contact (Agent)' - }, - { - value: 'last_contact_customer_at' - name: 'Last contact (Customer)' - }, - { - value: 'first_response_at' - name: 'First Response' - }, - { - value: 'close_at' - name: 'Close time' - }, - { - value: 'article_count' - name: 'Article Count' - }, - { - value: 'updated_at' - name: 'Updated at' - }, - { - value: 'created_at' - name: 'Created at' - }, - ] - class: 'medium' }, - { - name: 'order::by', + name: 'order::by', display: 'Order', - tag: 'select' + tag: 'selectTicketAttributes' default: 'created_at' null: false translate: true - options: - number: 'Number' - title: 'Title' - customer: 'Customer' - state: 'State' - priority: 'Priority' - group: 'Group' - owner: 'Owner' - last_contact_at: 'Last contact' - last_contact_agent_at: 'Last contact (Agent)' - last_contact_customer_at: 'Last contact (Customer)' - first_response_at: 'First Response' - close_at: 'Close time' - article_count: 'Article Count' - updated_at: 'Updated at' - created_at: 'Created at' - class: 'span4' }, { name: 'order::direction' @@ -117,7 +36,6 @@ class App.Overview extends App.Model options: ASC: 'up' DESC: 'down' - class: 'span4' }, { name: 'group_by' @@ -133,7 +51,6 @@ class App.Overview extends App.Model priority: 'Priority' group: 'Group' owner: 'Owner' - class: 'span4' }, { name: 'active', display: 'Active', tag: 'active', default: true }, { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },