diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index 1b3a4567b..ddab7cc4c 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -1,7 +1,4 @@ class App.OrganizationZoom extends App.Controller - elements: - '.tabsSidebar' : 'sidebar' - constructor: (params) -> super @@ -12,7 +9,11 @@ class App.OrganizationZoom extends App.Controller @navupdate '#' - App.Organization.full( @organization_id, @render ) + # subscribe and reload data / fetch new data if triggered + @subscribeId = App.Organization.full( @organization_id, @render, false, true ) + + release: => + App.Organization.unsubscribe(@subscribeId) meta: => meta = @@ -36,10 +37,7 @@ class App.OrganizationZoom extends App.Controller @navupdate '#' changed: => - formCurrent = @formParam( @el.find('.ticket-update') ) - diff = difference( @formDefault, formCurrent ) - return false if !diff || _.isEmpty( diff ) - return true + false render: (organization) => @@ -47,12 +45,38 @@ class App.OrganizationZoom extends App.Controller @doNotLog = 1 @recentView( 'Organization', @organization_id ) + # get display data + organizationData = [] + for item2 in App.Organization.configure_attributes + item = _.clone( item2 ) + + # check if value for _id exists + itemNameValue = item.name + itemNameValueNew = itemNameValue.substr( 0, itemNameValue.length - 3 ) + if itemNameValueNew of organization + item.name = itemNameValueNew + + # add to show if value exists + if organization[item.name] || item.tag is 'textarea' + + # do not show firstname and lastname / already show via diplayName() + if item.name isnt 'name' + if item.info + organizationData.push item + @html App.view('organization_zoom')( - organization: organization + organization: organization + organizationData: organizationData ) - new Overviews( - el: @el + @$('[contenteditable]').ce({ + mode: 'textonly' + multiline: true + maxlength: 250 + }) + + new App.TicketStats( + el: @$('.js-ticket-stats') organization: organization ) @@ -60,125 +84,38 @@ class App.OrganizationZoom extends App.Controller genericObject: organization ) - new App.UpdateHeader( - el: @el - genericObject: organization - ) - # start action controller showHistory = => new App.OrganizationHistory( organization_id: organization.id ) + editOrganization = => + new App.ControllerGenericEdit( + id: organization.id + genericObject: 'Organization' + screen: 'edit' + pageData: + title: 'Organizations' + object: 'Organization' + objects: 'Organizations' + ) actions = [ + { + name: 'edit' + title: 'Edit' + callback: editOrganization + } { name: 'history' title: 'History' callback: showHistory } ] + new App.ActionRow( el: @el.find('.action') items: actions ) - new Sidebar( - el: @sidebar - organization: organization - ) - -class Overviews extends App.Controller - constructor: -> - super - - # subscribe and reload data / fetch new data if triggered - @subscribeId = App.Organization.full( @organization.id, @render, false, true ) - - release: => - App.Organization.unsubscribe(@subscribeId) - - render: (organization) => - - plugins = - main: - my_organization: - controller: App.DashboardTicketSearch, - params: - name: 'Tickets of Organization' - condition: - 'tickets.state_id': [ 1,2,3,4,6 ] - 'tickets.organization_id': organization.id - order: - by: 'created_at' - direction: 'DESC' - view: - d: [ 'number', 'title', 'customer', 'state', 'priority', 'created_at' ] - view_mode_default: 'd' - - for area, plugins of plugins - for name, plugin of plugins - target = area + '_' + name - @el.find('.' + area + '-overviews').append('
') - if plugin.controller - params = plugin.params || {} - params.el = @el.find( '#' + target ) - new plugin.controller( params ) - - dndOptions = - handle: 'h2.can-move' - placeholder: 'can-move-plcaeholder' - tolerance: 'pointer' - distance: 15 - opacity: 0.6 - forcePlaceholderSize: true - - @el.find( '#sortable' ).sortable( dndOptions ) - @el.find( '#sortable-sidebar' ).sortable( dndOptions ) - - -class Sidebar extends App.Controller - constructor: -> - super - - # render ui - @render() - - render: -> - - items = [] - - editOrganization = (e, el) => - new App.ControllerGenericEdit( - id: @organization.id - genericObject: 'Organization' - pageData: - title: 'Organizations' - object: 'Organization' - objects: 'Organizations' - ) - showOrganization = (el) => - new App.WidgetOrganization( - el: el - organization_id: @organization.id - ) - items.push { - head: 'Organization' - name: 'organization' - icon: 'group' - actions: [ - { - name: 'Edit Organization' - class: 'glyphicon glyphicon-edit' - callback: editOrganization - }, - ] - callback: showOrganization - } - - new App.Sidebar( - el: @el - items: items - ) - class Router extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index 8490c4844..be7cad668 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -77,12 +77,7 @@ class App.UserZoom extends App.Controller maxlength: 250 }) - #new Overviews( - # el: @el - # user: user - #) - - new TicketStats( + new App.TicketStats( el: @$('.js-ticket-stats') user: user ) @@ -132,220 +127,6 @@ class App.UserZoom extends App.Controller user.updateAttributes( note: note ) @log 'notice', 'update', e, note, user - -class TicketStats extends App.Controller - events: - 'click .js-userTab': 'showUserTab' - 'click .js-orgTab': 'showOrgTab' - - constructor: -> - super - - # subscribe and reload data / fetch new data if triggered - @subscribeId = App.User.full( @user.id, @load, false, true ) - - release: => - App.User.unsubscribe(@subscribeId) - - load: (user) => - @ajax( - id: 'ticket_stats_' + user.id, - type: 'GET', - url: @apiPath + '/ticket_stats/' + user.id, - success: (data) => - # load assets - App.Collection.loadAssets( data.assets ) - - @render(data) - ) - - showOrgTab: => - @$('.js-userTab').removeClass('active') - @$('.js-orgTab').addClass('active') - @$('.js-user').addClass('hide') - @$('.js-org').removeClass('hide') - - showUserTab: => - @$('.js-userTab').addClass('active') - @$('.js-orgTab').removeClass('active') - @$('.js-user').removeClass('hide') - @$('.js-org').addClass('hide') - - render: (data) => - - @html App.view('user_zoom/ticket_stats')( - user: @user - ) - - limit = 5 - new TicketStatsList( - el: @$('.js-user-open-tickets') - user: @user - head: 'Open Ticket' - ticket_ids: data.user_tickets_open_ids - limit: limit - ) - new TicketStatsList( - el: @$('.js-user-closed-tickets') - user: @user - head: 'Closed Ticket' - ticket_ids: data.user_tickets_closed_ids - limit: limit - ) - new TicketStatsFrequency( - el: @$('.js-user-frequency') - user: @user - ticket_volume_by_year: data.user_ticket_volume_by_year - ) - - new TicketStatsList( - el: @$('.js-org-open-tickets') - user: @user - head: 'Open Ticket' - ticket_ids: data.org_tickets_open_ids - limit: limit - ) - new TicketStatsList( - el: @$('.js-org-closed-tickets') - user: @user - head: 'Closed Ticket' - ticket_ids: data.org_tickets_closed_ids - limit: limit - ) - new TicketStatsFrequency( - el: @$('.js-org-frequency') - user: @user - ticket_volume_by_year: data.org_ticket_volume_by_year - ) - -class TicketStatsList extends App.Controller - events: - 'click .js-showAll': 'showAll' - - constructor: -> - super - @render() - - render: => - - ticket_ids_show = [] - if !@all - count = 0 - for ticket_id in @ticket_ids - count += 1 - if count <= @limit - ticket_ids_show.push ticket_id - else - ticket_ids_show = @ticket_ids - - @html App.view('user_zoom/ticket_stats_list')( - user: @user - head: @head - ticket_ids: @ticket_ids - ticket_ids_show: ticket_ids_show - limit: @limit - ) - @frontendTimeUpdate() - @ticketPopups() - - showAll: (e) => - e.preventDefault() - @all = true - @render() - -class TicketStatsFrequency extends App.Controller - constructor: -> - super - @render() - - render: (data) => - - # find 100% - max = 0 - for item in @ticket_volume_by_year - if item.closed > max - max = item.closed - if item.created > max - max = item.created - console.log('MM', max) - for item in @ticket_volume_by_year - item.created_in_percent = 100 / max * item.created - item.closed_in_percent = 100 / max * item.closed - - @html App.view('user_zoom/ticket_stats_frequency')( - user: @user - ticket_volume_by_year: @ticket_volume_by_year.reverse() - ) - -class Overviews extends App.Controller - constructor: -> - super - - # subscribe and reload data / fetch new data if triggered - @subscribeId = App.User.full( @user.id, @render, false, true ) - - release: => - App.User.unsubscribe(@subscribeId) - - render: (user) => - - plugins = { - main: { - my_assigned: { - controller: App.DashboardTicketSearch, - params: { - name: 'Tickets of User' - condition: - 'tickets.state_id': [ 1,2,3,4,6 ] - 'tickets.customer_id': user.id - order: - by: 'created_at' - direction: 'DESC' - view: - d: [ 'number', 'title', 'state', 'priority', 'created_at' ] - view_mode_default: 'd' - }, - }, - }, - } - if user.organization_id - plugins.main.my_organization = { - controller: App.DashboardTicketSearch, - params: { - name: 'Tickets of Organization' - condition: - 'tickets.state_id': [ 1,2,3,4,6 ] - 'tickets.organization_id': user.organization_id - order: - by: 'created_at' - direction: 'DESC' - view: - d: [ 'number', 'title', 'customer', 'state', 'priority', 'created_at' ] - view_mode_default: 'd' - }, - } - - for area, plugins of plugins - for name, plugin of plugins - target = area + '_' + name - @el.find('.' + area + '-overviews').append('') - if plugin.controller - params = plugin.params || {} - params.el = @el.find( '#' + target ) - new plugin.controller( params ) - - dndOptions = - handle: 'h2.can-move' - placeholder: 'can-move-plcaeholder' - tolerance: 'pointer' - distance: 15 - opacity: 0.6 - forcePlaceholderSize: true - - @el.find( '#sortable' ).sortable( dndOptions ) - @el.find( '#sortable-sidebar' ).sortable( dndOptions ) - - class Router extends App.ControllerPermanent constructor: (params) -> super diff --git a/app/assets/javascripts/app/controllers/widget/ticket_stats.js.coffee b/app/assets/javascripts/app/controllers/widget/ticket_stats.js.coffee new file mode 100644 index 000000000..53904cc51 --- /dev/null +++ b/app/assets/javascripts/app/controllers/widget/ticket_stats.js.coffee @@ -0,0 +1,161 @@ +class App.TicketStats extends App.Controller + events: + 'click .js-userTab': 'showUserTab' + 'click .js-orgTab': 'showOrgTab' + + constructor: -> + super + + # subscribe and reload data / fetch new data if triggered + if @user + @subscribeId = App.User.full( @user.id, @load, false, true ) + if @organization + @subscribeId = App.Organization.full( @organization.id, @load, false, true ) + + release: => + App.User.unsubscribe(@subscribeId) + + load: (object) => + if @organization + ajaxKey = "org_" + @organization.id + data = + organization_id: @organization.id + else + ajaxKey = "user_" + @user.id + data = + user_id: @user.id + organization_id: @user.organization_id + @ajax( + id: 'ticket_stats_' + ajaxKey + type: 'GET' + url: @apiPath + '/ticket_stats' + data: data + processData: true + success: (data) => + # load assets + App.Collection.loadAssets( data.assets ) + + @render(data) + ) + + showOrgTab: => + @$('.js-userTab').removeClass('active') + @$('.js-orgTab').addClass('active') + @$('.js-user').addClass('hide') + @$('.js-org').removeClass('hide') + + showUserTab: => + @$('.js-userTab').addClass('active') + @$('.js-orgTab').removeClass('active') + @$('.js-user').removeClass('hide') + @$('.js-org').addClass('hide') + + render: (data) => + + @html App.view('widget/ticket_stats')( + user: @user + organization: @organization + ) + + if @organization + @showOrgTab() + + limit = 5 + new TicketStatsList( + el: @$('.js-user-open-tickets') + user: @user + head: 'Open Ticket' + ticket_ids: data.user_tickets_open_ids + limit: limit + ) + new TicketStatsList( + el: @$('.js-user-closed-tickets') + user: @user + head: 'Closed Ticket' + ticket_ids: data.user_tickets_closed_ids + limit: limit + ) + new TicketStatsFrequency( + el: @$('.js-user-frequency') + user: @user + ticket_volume_by_year: data.user_ticket_volume_by_year + ) + + new TicketStatsList( + el: @$('.js-org-open-tickets') + user: @user + head: 'Open Ticket' + ticket_ids: data.org_tickets_open_ids + limit: limit + ) + new TicketStatsList( + el: @$('.js-org-closed-tickets') + user: @user + head: 'Closed Ticket' + ticket_ids: data.org_tickets_closed_ids + limit: limit + ) + new TicketStatsFrequency( + el: @$('.js-org-frequency') + user: @user + ticket_volume_by_year: data.org_ticket_volume_by_year + ) + +class TicketStatsList extends App.Controller + events: + 'click .js-showAll': 'showAll' + + constructor: -> + super + @render() + + render: => + + ticket_ids_show = [] + if !@all + count = 0 + for ticket_id in @ticket_ids + count += 1 + if count <= @limit + ticket_ids_show.push ticket_id + else + ticket_ids_show = @ticket_ids + + @html App.view('widget/ticket_stats_list')( + user: @user + head: @head + ticket_ids: @ticket_ids + ticket_ids_show: ticket_ids_show + limit: @limit + ) + @frontendTimeUpdate() + @ticketPopups() + + showAll: (e) => + e.preventDefault() + @all = true + @render() + +class TicketStatsFrequency extends App.Controller + constructor: -> + super + @render() + + render: (data) => + + # find 100% + max = 0 + for item in @ticket_volume_by_year + if item.closed > max + max = item.closed + if item.created > max + max = item.created + + for item in @ticket_volume_by_year + item.created_in_percent = 100 / max * item.created + item.closed_in_percent = 100 / max * item.closed + + @html App.view('widget/ticket_stats_frequency')( + user: @user + ticket_volume_by_year: @ticket_volume_by_year.reverse() + ) diff --git a/app/assets/javascripts/app/views/organization_zoom.jst.eco b/app/assets/javascripts/app/views/organization_zoom.jst.eco index c2cf224d6..24d314255 100644 --- a/app/assets/javascripts/app/views/organization_zoom.jst.eco +++ b/app/assets/javascripts/app/views/organization_zoom.jst.eco @@ -1,18 +1,49 @@ -