From a937196a499eac13869c2a01ef27ac8a44a176dd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 22 Jul 2014 11:00:29 +0200 Subject: [PATCH] Init version of organization zoom. --- .../organization_history.js.coffee | 20 ++++ .../controllers/organization_zoom.js.coffee | 98 +++++++++++++++++++ .../app/controllers/user_zoom.js.coffee | 4 +- .../app/views/organization_zoom.jst.eco | 18 ++++ .../javascripts/app/views/user_zoom.jst.eco | 9 +- app/controllers/organizations_controller.rb | 22 ++++- app/models/history.rb | 1 + app/models/ticket.rb | 8 +- config/routes/organization.rb | 1 + 9 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/organization_history.js.coffee create mode 100644 app/assets/javascripts/app/controllers/organization_zoom.js.coffee create mode 100644 app/assets/javascripts/app/views/organization_zoom.jst.eco diff --git a/app/assets/javascripts/app/controllers/organization_history.js.coffee b/app/assets/javascripts/app/controllers/organization_history.js.coffee new file mode 100644 index 000000000..0504a0718 --- /dev/null +++ b/app/assets/javascripts/app/controllers/organization_history.js.coffee @@ -0,0 +1,20 @@ +class App.OrganizationHistory extends App.GenericHistory + constructor: -> + super + @fetch() + + fetch: -> + + # get data + @ajax( + id: 'organization_history', + type: 'GET', + url: @apiPath + '/organizations/history/' + @organization_id, + success: (data, status, xhr) => + + # load assets + App.Collection.loadAssets( data.assets ) + + # render page + @render(data.history) + ) diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee new file mode 100644 index 000000000..bc0a38f06 --- /dev/null +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -0,0 +1,98 @@ +class App.OrganizationZoom extends App.Controller + constructor: (params) -> + super + + # check authentication + return if !@authenticate() + + @navupdate '#' + + start = (organization) => + @organization = organization + @render() + + App.Organization.retrieve( @organization_id, start, true ) + + meta: => + meta = + url: @url() + id: @organization_id + if @organization + meta.head = @organization.displayName() + meta.title = @organization.displayName() + meta + + url: => + '#organization/zoom/' + @organization_id + + activate: => + @navupdate '#' + + changed: => + formCurrent = @formParam( @el.find('.ticket-update') ) + diff = difference( @formDefault, formCurrent ) + return false if !diff || _.isEmpty( diff ) + return true + + release: => + # nothing + + render: => + # update taskbar with new meta data + App.Event.trigger 'task:render' + + @html App.view('organization_zoom')( + organization: @organization + ) + + # start action controller + new ActionRow( + el: @el.find('.action') + organization: @organization + ui: @ + ) + + new Widgets( + el: @el.find('.widgets') + organization: @organization + ui: @ + ) + +class Widgets extends App.Controller + constructor: -> + super + @render() + + render: -> + + new App.WidgetOrganization( + el: @el + organization_id: @organization.id + ) + +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 + + # cleanup params + clean_params = + organization_id: params.organization_id + + App.TaskManager.add( 'Organization-' + @organization_id, 'OrganizationZoom', clean_params ) + +App.Config.set( 'organization/zoom/:organization_id', Router, 'Routes' ) diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index a23b33403..1d3cc6846 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -66,10 +66,8 @@ class Widgets extends App.Controller render: -> - @html App.view('user_zoom/widgets')() - new App.WidgetUser( - el: @el.find('.user_info') + el: @el user_id: @user.id ) diff --git a/app/assets/javascripts/app/views/organization_zoom.jst.eco b/app/assets/javascripts/app/views/organization_zoom.jst.eco new file mode 100644 index 000000000..ffa1a0d7e --- /dev/null +++ b/app/assets/javascripts/app/views/organization_zoom.jst.eco @@ -0,0 +1,18 @@ +
+ +
+ + + +
+
+
+
+ +
+
\ 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 8c77dfc41..c369d5943 100644 --- a/app/assets/javascripts/app/views/user_zoom.jst.eco +++ b/app/assets/javascripts/app/views/user_zoom.jst.eco @@ -5,10 +5,8 @@
- -
- + \ No newline at end of file diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index fafb1f393..ce9e5ddb7 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -168,4 +168,24 @@ Test: return if deny_if_not_role('Agent') model_destory_render(Organization, params) end -end + + # GET /api/v1/organizations/history/1 + def history + + # permissin check + if !is_role('Admin') && !is_role('Agent') + response_access_deny + return + end + + # get organization data + organization = Organization.find( params[:id] ) + + # get history of organization + history = organization.history_get(true) + + # return result + render :json => history + end + +end \ No newline at end of file diff --git a/app/models/history.rb b/app/models/history.rb index 5da5b964b..578f1c457 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -1,6 +1,7 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ class History < ApplicationModel + require 'history/assets' include History::Assets self.table_name = 'histories' diff --git a/app/models/ticket.rb b/app/models/ticket.rb index e2364d933..cc78eb2a4 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -4,13 +4,13 @@ class Ticket < ApplicationModel include Ticket::Escalation include Ticket::Subject include Ticket::Permission - load 'ticket/assets.rb' + require 'ticket/assets' include Ticket::Assets - load 'ticket/history_log.rb' + require 'ticket/history_log' include Ticket::HistoryLog - load 'ticket/activity_stream_log.rb' + require 'ticket/activity_stream_log' include Ticket::ActivityStreamLog - load 'ticket/search_index.rb' + require 'ticket/search_index' include Ticket::SearchIndex extend Ticket::Search diff --git a/config/routes/organization.rb b/config/routes/organization.rb index 444749c0a..7181e6cf3 100644 --- a/config/routes/organization.rb +++ b/config/routes/organization.rb @@ -6,5 +6,6 @@ Zammad::Application.routes.draw do match api_path + '/organizations/:id', :to => 'organizations#show', :via => :get match api_path + '/organizations', :to => 'organizations#create', :via => :post match api_path + '/organizations/:id', :to => 'organizations#update', :via => :put + match api_path + '/organizations/history/:id',:to => 'organizations#history',:via => :get end \ No newline at end of file