From 3ed77d985eea4ce20fd6f9719fee9e880fdb8368 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 21 Sep 2014 21:58:07 +0200 Subject: [PATCH] Improved modal and added generic actions. --- .../_application_controller.js.coffee | 1 - .../_application_controller_generic.js.coffee | 129 +++++++++++++----- .../controllers/agent_ticket_merge.js.coffee | 8 +- .../organization_history.js.coffee | 6 +- .../controllers/organization_zoom.js.coffee | 32 ++--- .../app/controllers/ticket_history.js.coffee | 8 +- .../app/controllers/ticket_zoom.js.coffee | 55 +++----- .../app/controllers/user_history.js.coffee | 4 +- .../app/controllers/user_zoom.js.coffee | 33 ++--- .../app/controllers/widget/link.js.coffee | 77 ++++++++++- .../app/views/agent_ticket_merge.jst.eco | 36 ++--- .../{user_zoom => generic}/actions.jst.eco | 4 +- .../app/views/generic/history.jst.eco | 48 ++----- .../javascripts/app/views/link/add.jst.eco | 14 +- .../app/views/organization_zoom.jst.eco | 24 ++-- .../app/views/ticket_zoom/actions.jst.eco | 8 -- .../javascripts/app/views/user_zoom.jst.eco | 1 - app/controllers/tickets_controller.rb | 15 +- app/models/recent_view.rb | 14 +- config/routes/ticket.rb | 2 +- 20 files changed, 297 insertions(+), 222 deletions(-) rename app/assets/javascripts/app/views/{user_zoom => generic}/actions.jst.eco (59%) delete mode 100644 app/assets/javascripts/app/views/ticket_zoom/actions.jst.eco diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 0b3762346..648f222e5 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -456,7 +456,6 @@ class App.ControllerModal extends App.Controller @show() show: -> - console.log('M', @message, @el.length) if @button is true @button = 'Submit' diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index fed8e74cc..51ad826d9 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -359,41 +359,21 @@ class App.GenericHistory extends App.ControllerModal @head = 'History' @close = true - render: ( items, orderClass = '' ) -> + render: -> - for item in items - - item.link = '' - item.title = '???' - - if item.object is 'Ticket::Article' - item.object = 'Article' - article = App.TicketArticle.find( item.o_id ) - ticket = App.Ticket.find( article.ticket_id ) - item.title = article.subject || ticket.title - item.link = article.uiUrl() - - if App[item.object] - object = App[item.object].find( item.o_id ) - item.link = object.uiUrl() - item.title = object.displayName() - - item.created_by = App.User.find( item.created_by_id ) - - # set cache - @historyListCache = items + localItem = @reworkItems( @items ) @html App.view('generic/history')( - items: items - orderClass: orderClass - - @historyListCache + items: localItem ) + + @onShow() + @el.find('a[data-type="sortorder"]').bind( 'click', (e) => e.preventDefault() - @sortorder(e) + @sortorder() ) if !@isShown @isShown = true @@ -404,16 +384,95 @@ class App.GenericHistory extends App.ControllerModal @userPopups() # show frontend times - @delay( @frontendTimeUpdate, 100, 'ui-time-update' ) + @delay( @frontendTimeUpdate, 800, 'ui-time-update' ) - sortorder: (e) -> - e.preventDefault() - isDown = @el.find('[data-type="sortorder"]').hasClass('down') + sortorder: => + @items = @items.reverse() - if isDown - @render( @historyListCache, 'up' ) - else - @render( @historyListCache.reverse(), 'down' ) + @render() + + T: (name) -> + App.i18n.translateInline(name) + + reworkItems: (items) -> + newItems = [] + newItem = {} + lastUserId = undefined + lastTime = undefined + items = clone(items) + for item in items + + if item.object is 'Ticket::Article' + item.object = 'Article' + + data = item + data.created_by = App.User.find( item.created_by_id ) + + currentItemTime = new Date( item.created_at ) + lastItemTime = new Date( new Date( lastTime ).getTime() + (15 * 1000) ) + + # start new section if user or time has changed + if lastUserId isnt item.created_by_id || currentItemTime > lastItemTime + lastTime = item.created_at + lastUserId = item.created_by_id + if !_.isEmpty(newItem) + newItems.push newItem + newItem = + created_at: item.created_at + created_by: App.User.find( item.created_by_id ) + records: [] + + # build content + content = '' + if item.type is 'notification' || item.type is 'email' + content = "#{ @T( item.type ) } #{ @T( 'sent to' ) } #{ item.value_to }" + else + content = "#{ @T( item.type ) } #{ @T(item.object) } " + if item.attribute + content += "#{ @T(item.attribute) }" + + # convert time stamps + if item.object is 'User' && item.attribute is 'last_login' + if item.value_from + item.value_from = App.i18n.translateTimestamp( item.value_from ) + if item.value_to + item.value_to = App.i18n.translateTimestamp( item.value_to ) + + if item.value_from + if item.value_to + content += " #{ @T( 'from' ) }" + content += " '#{ item.value_from }'" + + if item.value_to + if item.value_from + content += " #{ @T( 'to' ) }" + content += " '#{ item.value_to }'" + + newItem.records.push content + + if !_.isEmpty(newItem) + newItems.push newItem + + newItems + +class App.ActionRow extends App.Controller + constructor: -> + super + @render() + + render: -> + @html App.view('generic/actions')( + items: @items + ) + + for item in @items + do (item) => + @el.find('[data-type="' + item.name + '"]').on( + 'click', + (e) => + e.preventDefault() + item.callback() + ) class App.Sidebar extends App.Controller events: diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee index 09d4e9038..cdb748b58 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -1,15 +1,18 @@ class App.TicketMerge extends App.ControllerModal constructor: -> super + @head = 'Merge' + @button = true + @cancel = true @fetch() fetch: -> # merge tickets @ajax( - id: 'ticket_merge_list' + id: 'ticket_related' type: 'GET' - url: @apiPath + '/ticket_merge_list/' + @ticket.id + url: @apiPath + '/ticket_related/' + @ticket.id processData: true, success: (data, status, xhr) => @@ -18,7 +21,6 @@ class App.TicketMerge extends App.ControllerModal @ticket_ids_by_customer = data.ticket_ids_by_customer @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed - @render() ) diff --git a/app/assets/javascripts/app/controllers/organization_history.js.coffee b/app/assets/javascripts/app/controllers/organization_history.js.coffee index 0504a0718..a88953a15 100644 --- a/app/assets/javascripts/app/controllers/organization_history.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_history.js.coffee @@ -15,6 +15,8 @@ class App.OrganizationHistory extends App.GenericHistory # load assets App.Collection.loadAssets( data.assets ) + @items = data.history + # render page - @render(data.history) - ) + @render() + ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index 025bf41fa..f7c0647ee 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -64,10 +64,19 @@ class App.OrganizationZoom extends App.Controller ) # start action controller - new ActionRow( - el: @el.find('.action') - organization: organization - ui: @ + showHistory = => + new App.OrganizationHistory( organization_id: organization.id ) + + actions = [ + { + name: 'history' + title: 'History' + callback: showHistory + } + ] + new App.ActionRow( + el: @el.find('.action') + items: actions ) new Sidebar( @@ -168,21 +177,6 @@ class Sidebar extends App.Controller items: items ) -class ActionRow extends App.Controller - events: - 'click [data-type=history]': 'history_dialog' - - constructor: -> - super - @render() - - render: -> - @html App.view('user_zoom/actions')() - - history_dialog: (e) -> - e.preventDefault() - new App.OrganizationHistory( organization_id: @organization.id ) - class Router extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/ticket_history.js.coffee b/app/assets/javascripts/app/controllers/ticket_history.js.coffee index 1e2a5f6c7..2cd33cc60 100644 --- a/app/assets/javascripts/app/controllers/ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_history.js.coffee @@ -9,12 +9,14 @@ class App.TicketHistory extends App.GenericHistory @ajax( id: 'ticket_history', type: 'GET', - url: @apiPath + '/ticket_history/' + @ticket.id, + url: @apiPath + '/ticket_history/' + @ticket_id, success: (data, status, xhr) => # load assets App.Collection.loadAssets( data.assets ) + @items = data.history + # render page - @render(data.history) - ) + @render() + ) \ No newline at end of file diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 3c7f76773..c7617aba9 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -162,6 +162,28 @@ class App.TicketZoom extends App.Controller object_type: 'Ticket' object: @ticket ) + el.append('
') + showHistory = => + new App.TicketHistory( ticket_id: @ticket.id ) + showMerge = => + new App.TicketMerge( ticket: @ticket, task_key: @task_key ) + actions = [ + { + name: 'history' + title: 'History' + callback: showHistory + }, + { + name: 'merge' + title: 'Merge' + callback: showMerge + }, + ] + new App.ActionRow( + el: @el.find('.action') + items: actions + ) + items = [ { head: 'Ticket Settings' @@ -275,7 +297,6 @@ class App.TicketZoom extends App.Controller ) ### - @TicketAction() @ArticleView() if force || !@editDone @@ -323,18 +344,6 @@ class App.TicketZoom extends App.Controller ui: @ ) - TicketAction: => - # start action controller - if !@isRole('Customer') - new ActionRow( - el: @el.find('.action') - ticket: @ticket - ui: @ - ) - - # enable user popups - @userPopups() - class TicketTitle extends App.Controller events: 'blur .ticket-title-update': 'update' @@ -1212,26 +1221,6 @@ class Article extends App.Controller for attachment in @article.attachments attachment.size = @humanFileSize(attachment.size) -class ActionRow extends App.Controller - events: - 'click [data-type=history]': 'history_dialog' - 'click [data-type=merge]': 'merge_dialog' - - constructor: -> - super - @render() - - render: -> - @html App.view('ticket_zoom/actions')() - - history_dialog: (e) -> - e.preventDefault() - new App.TicketHistory( ticket: @ticket ) - - merge_dialog: (e) -> - e.preventDefault() - new App.TicketMerge( ticket: @ticket, task_key: @ui.task_key ) - class TicketZoomRouter extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/user_history.js.coffee b/app/assets/javascripts/app/controllers/user_history.js.coffee index 6083dd746..5890082ce 100644 --- a/app/assets/javascripts/app/controllers/user_history.js.coffee +++ b/app/assets/javascripts/app/controllers/user_history.js.coffee @@ -15,6 +15,8 @@ class App.UserHistory extends App.GenericHistory # load assets App.Collection.loadAssets( data.assets ) + @items = data.history + # render page - @render(data.history) + @render() ) diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index 166e2072f..74c2b485a 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -63,10 +63,19 @@ class App.UserZoom extends App.Controller ) # start action controller - new ActionRow( - el: @el.find('.action') - user: user - ui: @ + showHistory = => + new App.UserHistory( user_id: user.id ) + + actions = [ + { + name: 'history' + title: 'History' + callback: showHistory + } + ] + new App.ActionRow( + el: @el.find('.action') + items: actions ) new Sidebar( @@ -218,22 +227,6 @@ class Sidebar extends App.Controller items: items ) -class ActionRow extends App.Controller - events: - 'click [data-type=history]': 'history_dialog' - - constructor: -> - super - @render() - - render: -> - @html App.view('user_zoom/actions')() - - history_dialog: (e) -> - e.preventDefault() - new App.UserHistory( user_id: @user.id ) - - class Router extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/widget/link.js.coffee b/app/assets/javascripts/app/controllers/widget/link.js.coffee index 645cd27ac..9840f1d28 100644 --- a/app/assets/javascripts/app/controllers/widget/link.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/link.js.coffee @@ -74,10 +74,10 @@ class App.WidgetLink extends App.Controller add: (e) => e.preventDefault() new App.LinkAdd( - link_object: @object_type, - link_object_id: @object.id, - object: @object, - parent: @, + link_object: @object_type + link_object_id: @object.id + object: @object + parent: @ ) class App.LinkAdd extends App.ControllerModal @@ -87,17 +87,86 @@ class App.LinkAdd extends App.ControllerModal @button = true @cancel = true + @ticket = @object + + @fetch() + + fetch: -> + + # merge tickets + @ajax( + id: 'ticket_related' + type: 'GET' + url: @apiPath + '/ticket_related/' + @ticket.id + processData: true, + success: (data, status, xhr) => + + # load assets + App.Collection.loadAssets( data.assets ) + + @ticket_ids_by_customer = data.ticket_ids_by_customer + @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed + @render() + ) + + + render: -> @html App.view('link/add')( link_object: @link_object, link_object_id: @link_object_id, object: @object, ) + + list = [] + for ticket_id in @ticket_ids_by_customer + if ticket_id isnt @ticket.id + ticketItem = App.Ticket.fullLocal( ticket_id ) + list.push ticketItem + new App.ControllerTable( + el: @el.find('#ticket-merge-customer-tickets'), + overview: [ 'number', 'title', 'state', 'group', 'created_at' ] + model: App.Ticket, + objects: list, + radio: true, + ) + + list = [] + for ticket_id in @ticket_ids_recent_viewed + if ticket_id isnt @ticket.id + ticketItem = App.Ticket.fullLocal( ticket_id ) + list.push ticketItem + new App.ControllerTable( + el: @el.find('#ticket-merge-recent-tickets'), + overview: [ 'number', 'title', 'state', 'group', 'created_at' ] + model: App.Ticket, + objects: list, + radio: true, + ) + + @el.delegate('[name="ticket_number"]', 'focus', (e) -> + $(e.target).parents().find('[name="radio"]').prop( 'checked', false ) + ) + + @el.delegate('[name="radio"]', 'click', (e) -> + if $(e.target).prop('checked') + ticket_id = $(e.target).val() + ticket = App.Ticket.fullLocal( ticket_id ) + $(e.target).parents().find('[name="ticket_number"]').val( ticket.number ) + ) + @show() onSubmit: (e) => e.preventDefault() params = @formParam(e.target) + if !params['ticket_number'] + alert('Ticket# is needed!') + return + if !params['link_type'] + alert('Link type is needed!') + return + # get data @ajax( id: 'links_add_' + @object.id + '_' + @object_type, diff --git a/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco b/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco index ce11d67c8..fb77665ac 100644 --- a/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_merge.jst.eco @@ -1,26 +1,10 @@ -
- -
+
+

<%- @T( 'Merge to Ticket#' ) %>

+ +
+

<%- @T( 'Recent Customer Tickets' ) %>

+
+
+

<%- @T( 'Recent viewed Tickets' ) %>

+
+
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/user_zoom/actions.jst.eco b/app/assets/javascripts/app/views/generic/actions.jst.eco similarity index 59% rename from app/assets/javascripts/app/views/user_zoom/actions.jst.eco rename to app/assets/javascripts/app/views/generic/actions.jst.eco index 6b6fc5b79..be0018e1c 100644 --- a/app/assets/javascripts/app/views/user_zoom/actions.jst.eco +++ b/app/assets/javascripts/app/views/generic/actions.jst.eco @@ -1,6 +1,8 @@ \ No newline at end of file diff --git a/app/assets/javascripts/app/views/generic/history.jst.eco b/app/assets/javascripts/app/views/generic/history.jst.eco index e0985bff9..e1b3b8409 100644 --- a/app/assets/javascripts/app/views/generic/history.jst.eco +++ b/app/assets/javascripts/app/views/generic/history.jst.eco @@ -1,49 +1,17 @@
-<%- @T( 'Change order' ) %> +<%- @T( 'Change order' ) %>
-<% open = false %> <% for item in @items: %> - <% if lasttime isnt item['created_at'] || last_user isnt item['created_by_id']: %> - <% if open: %> - -
+ <%= item.created_by.displayName() %> - + ? +
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/link/add.jst.eco b/app/assets/javascripts/app/views/link/add.jst.eco index 69fcc06d5..409e89af9 100644 --- a/app/assets/javascripts/app/views/link/add.jst.eco +++ b/app/assets/javascripts/app/views/link/add.jst.eco @@ -12,11 +12,11 @@ <%- @T( 'of' ) %> Ticket# <%= @object.number %>. - + +
+

<%- @T( 'Recent Customer Tickets' ) %>

+
+
+

<%- @T( 'Recent viewed Tickets' ) %>

+
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/organization_zoom.jst.eco b/app/assets/javascripts/app/views/organization_zoom.jst.eco index 780dbaab6..9602bb896 100644 --- a/app/assets/javascripts/app/views/organization_zoom.jst.eco +++ b/app/assets/javascripts/app/views/organization_zoom.jst.eco @@ -1,12 +1,18 @@ -
-
- \ No newline at end of file diff --git a/app/assets/javascripts/app/views/ticket_zoom/actions.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/actions.jst.eco deleted file mode 100644 index f16073833..000000000 --- a/app/assets/javascripts/app/views/ticket_zoom/actions.jst.eco +++ /dev/null @@ -1,8 +0,0 @@ -
- - -
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/user_zoom.jst.eco b/app/assets/javascripts/app/views/user_zoom.jst.eco index fe4cc7253..a04ed077b 100644 --- a/app/assets/javascripts/app/views/user_zoom.jst.eco +++ b/app/assets/javascripts/app/views/user_zoom.jst.eco @@ -7,7 +7,6 @@
-
diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 69a619abf..436ddccc4 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -137,17 +137,24 @@ class TicketsController < ApplicationController render :json => history end - # GET /api/v1/ticket_merge_list/1 - def ticket_merge_list + # GET /api/v1/ticket_related/1 + def ticket_related ticket = Ticket.find( params[:ticket_id] ) assets = ticket.assets({}) # open tickets by customer + group_ids = Group.select( 'groups.id' ).joins(:users). + where( 'groups_users.user_id = ?', current_user.id ). + where( 'groups.active = ?', true ). + map( &:id ) + access_condition = [ 'group_id IN (?)', group_ids ] ticket_list = Ticket.where( :customer_id => ticket.customer_id, :state_id => Ticket::State.by_category( 'open' ) + ) + .where(access_condition) .where( 'id != ?', [ ticket.id ] ) .order('created_at DESC') .limit(6) @@ -161,9 +168,9 @@ class TicketsController < ApplicationController ticket_ids_recent_viewed = [] - ticket_recent_view = RecentView.list( current_user, 8 ) + ticket_recent_view = RecentView.list( current_user, 8, 'Ticket' ) ticket_recent_view.each {|item| - if item['recent_view_object'] == 'Ticket' + if item['object'] == 'Ticket' ticket_ids_recent_viewed.push item['o_id'] ticket = Ticket.find( item['o_id'] ) assets = ticket.assets(assets) diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index f7d4d88e5..79561cf4d 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -32,10 +32,16 @@ class RecentView < ApplicationModel RecentView.where( :created_by_id => user.id ).destroy_all end - def self.list( user, limit = 10 ) - recent_views = RecentView.where( :created_by_id => user.id ). - order('created_at DESC, id DESC'). - limit(limit) + def self.list( user, limit = 10, type = nil ) + if !type + recent_views = RecentView.where( :created_by_id => user.id ). + order('created_at DESC, id DESC'). + limit(limit) + else + recent_views = RecentView.select('DISTINCT(o_id), recent_view_object_id').where( :created_by_id => user.id, :recent_view_object_id => ObjectLookup.by_name(type) ) . + order('created_at DESC, id DESC'). + limit(limit) + end list = [] recent_views.each { |item| diff --git a/config/routes/ticket.rb b/config/routes/ticket.rb index f73b28e22..f638938ac 100644 --- a/config/routes/ticket.rb +++ b/config/routes/ticket.rb @@ -11,7 +11,7 @@ Zammad::Application.routes.draw do match api_path + '/ticket_full/:id', :to => 'tickets#ticket_full', :via => :get match api_path + '/ticket_history/:id', :to => 'tickets#ticket_history', :via => :get match api_path + '/ticket_customer', :to => 'tickets#ticket_customer', :via => :get - match api_path + '/ticket_merge_list/:ticket_id', :to => 'tickets#ticket_merge_list', :via => :get + match api_path + '/ticket_related/:ticket_id', :to => 'tickets#ticket_related', :via => :get match api_path + '/ticket_merge/:slave_ticket_id/:master_ticket_number', :to => 'tickets#ticket_merge', :via => :get # ticket overviews