mno-enterprise-frontend 2.0.9 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/mno_enterprise/angular/app.js.coffee.erb +0 -120
  3. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/maestrano-components.js.coffee +0 -11
  4. data/app/assets/javascripts/mno_enterprise/application.js +0 -2
  5. data/app/assets/javascripts/mno_enterprise/lib/xeditable.js +0 -0
  6. data/app/assets/stylesheets/mno_enterprise/main.less +0 -28
  7. data/app/views/layouts/mno_enterprise/_application_js.html.haml +0 -4
  8. data/app/views/layouts/mno_enterprise/_common_cdn_lib_js.html.haml +0 -5
  9. data/app/views/layouts/mno_enterprise/_header_files.html.haml +0 -3
  10. data/app/views/layouts/mno_enterprise/application.html.haml +1 -1
  11. data/app/views/mno_enterprise/provision/_provision_apps.html.haml +7 -8
  12. data/config/routes.rb +1 -10
  13. data/lib/mno_enterprise/frontend/engine.rb +12 -0
  14. data/lib/mno_enterprise/frontend/locales_generator.rb +57 -0
  15. data/lib/tasks/mnoe_admin_tasks.rake +67 -0
  16. data/lib/tasks/mnoe_frontend_tasks.rake +138 -0
  17. data/lib/tasks/mnoe_locales.rake +14 -0
  18. data/lib/tasks/templates/bower.json +10 -0
  19. data/spec/controllers/mno_enterprise/auth/confirmations_controller_spec.rb +2 -2
  20. data/spec/controllers/mno_enterprise/webhook/o_auth_controller_spec.rb +1 -1
  21. data/spec/lib/mno_enterprise/locales_generator_spec.rb +14 -0
  22. data/spec/lib/tasks/mnoe_locales_rake_spec.rb +25 -0
  23. metadata +35 -145
  24. data/app/assets/images/mno_enterprise/impac/close-widget-pink.png +0 -0
  25. data/app/assets/images/mno_enterprise/impac/close-widget.png +0 -0
  26. data/app/assets/javascripts/mno_enterprise/angular/controllers/maestrano-controllers.js.coffee +0 -4
  27. data/app/assets/javascripts/mno_enterprise/angular/controllers/modals/modals-ctrl.js.coffee +0 -62
  28. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-account.js.coffee +0 -157
  29. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-app-deletion-request.js.coffee +0 -62
  30. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-apps-list.js.coffee +0 -127
  31. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-components.js.coffee +0 -25
  32. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-marketplace-app.js.coffee +0 -77
  33. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-marketplace.js.coffee +0 -51
  34. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/dashboard-menu.js.coffee +0 -174
  35. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/arrears.js.coffee +0 -70
  36. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/billing.js.coffee +0 -48
  37. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/credit-card.js.coffee +0 -142
  38. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/index.js.coffee +0 -61
  39. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/invoices.js.coffee +0 -42
  40. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/members.js.coffee +0 -280
  41. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/settings.js.coffee +0 -91
  42. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/team-list.js.coffee +0 -179
  43. data/app/assets/javascripts/mno_enterprise/angular/directives/dashboard/organization/teams.js.coffee +0 -268
  44. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/file-model.js.coffee +0 -33
  45. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-autostop-app.js.coffee +0 -123
  46. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-currency-widget.js.coffee +0 -43
  47. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-current-currency.js.coffee +0 -22
  48. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-editable.js.coffee +0 -68
  49. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-helptext.js.coffee +0 -38
  50. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-match.js.coffee +0 -14
  51. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-message-modal.js.coffee +0 -56
  52. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-partner-code-popup.js.coffee +0 -74
  53. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-partner-contact.js.coffee +0 -59
  54. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-price-converter.js.coffee +0 -49
  55. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-scroll-to.js.coffee +0 -14
  56. data/app/assets/javascripts/mno_enterprise/angular/directives/maestrano-components/mno-typeahead.js.coffee +0 -89
  57. data/app/assets/javascripts/mno_enterprise/angular/directives/user-setup/components.js.coffee +0 -7
  58. data/app/assets/javascripts/mno_enterprise/angular/directives/user-setup/index.js.coffee +0 -256
  59. data/app/assets/javascripts/mno_enterprise/angular/filters/maestrano-app-by-category.js.coffee +0 -5
  60. data/app/assets/javascripts/mno_enterprise/angular/filters/maestrano-currency.js.coffee +0 -30
  61. data/app/assets/javascripts/mno_enterprise/angular/filters/maestrano-filters.js.coffee +0 -7
  62. data/app/assets/javascripts/mno_enterprise/angular/filters/maestrano-replace-underscore-with-space.js.coffee +0 -4
  63. data/app/assets/javascripts/mno_enterprise/angular/filters/maestrano-titleize.js.coffee +0 -7
  64. data/app/assets/javascripts/mno_enterprise/angular/filters/maestrano-truncate.js.coffee +0 -24
  65. data/app/assets/javascripts/mno_enterprise/angular/services/dashboard/maestrano-app-instance.js.coffee +0 -15
  66. data/app/assets/javascripts/mno_enterprise/angular/services/dashboard/maestrano-apps-document.js.coffee +0 -83
  67. data/app/assets/javascripts/mno_enterprise/angular/services/dashboard/maestrano-user.js.coffee +0 -27
  68. data/app/assets/javascripts/mno_enterprise/angular/services/dashboard/organization-svc.js.coffee +0 -318
  69. data/app/assets/javascripts/mno_enterprise/angular/services/dashboard/team-svc.js.coffee +0 -180
  70. data/app/assets/javascripts/mno_enterprise/angular/services/dashboard/tickets-svc.js.coffee +0 -109
  71. data/app/assets/javascripts/mno_enterprise/angular/services/impac-config.svc.js.coffee +0 -35
  72. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-apps-list-helper.js.coffee +0 -337
  73. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-current-currency.js.coffee +0 -7
  74. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-current-user-svc.js.coffee +0 -99
  75. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-exchange-rates.js.coffee +0 -102
  76. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-miscellaneous.js.coffee.erb +0 -46
  77. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-modal.js.coffee +0 -67
  78. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-services.js.coffee +0 -21
  79. data/app/assets/javascripts/mno_enterprise/angular/services/maestrano-shopping-cart.js.coffee +0 -361
  80. data/app/assets/javascripts/mno_enterprise/angular/services/marketplace-svc.js.coffee +0 -59
  81. data/app/assets/javascripts/mno_enterprise/lib/angular-really-click.js +0 -17
  82. data/app/assets/javascripts/ng-performance/ngPerformance.html +0 -109
  83. data/app/assets/javascripts/ng-performance/ngPerformance.js +0 -211
  84. data/app/assets/stylesheets/mno_enterprise/custom/impac-variables-override.less +0 -65
  85. data/app/assets/stylesheets/mno_enterprise/custom/utility/app-presentation.less +0 -77
  86. data/app/assets/stylesheets/mno_enterprise/custom/utility/banners.less +0 -145
  87. data/app/assets/stylesheets/mno_enterprise/custom/utility/carousel.less +0 -68
  88. data/app/assets/stylesheets/mno_enterprise/custom/utility/helptext.less +0 -40
  89. data/app/assets/stylesheets/mno_enterprise/custom/utility/miscellaneous.less +0 -134
  90. data/app/assets/stylesheets/mno_enterprise/custom/utility/testimonial.less +0 -118
  91. data/app/assets/stylesheets/mno_enterprise/custom/views/apps.less +0 -243
  92. data/app/assets/stylesheets/mno_enterprise/custom/views/myspace.less +0 -477
  93. data/app/assets/stylesheets/mno_enterprise/custom/views/pages/home.less +0 -57
  94. data/app/assets/stylesheets/mno_enterprise/custom/views/star.less +0 -18
  95. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/dashboard/bootstrap-wizard.less +0 -63
  96. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/dashboard/dashboard-marketplace.less +0 -187
  97. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/dashboard/dashboard-organization.less +0 -149
  98. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/dashboard/dashboard-teams.less +0 -119
  99. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/dashboard/support.less +0 -42
  100. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/dashboard/tickets.less +0 -80
  101. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/mno-editable.less +0 -60
  102. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/shopping-cart.less +0 -333
  103. data/app/assets/stylesheets/mno_enterprise/custom/views/templates/star-wizard.less +0 -49
  104. data/app/assets/stylesheets/mno_enterprise/custom/views/user-setup.less +0 -10
  105. data/app/assets/templates/mno_enterprise/dashboard/account.html +0 -131
  106. data/app/assets/templates/mno_enterprise/dashboard/app_deletion.html +0 -36
  107. data/app/assets/templates/mno_enterprise/dashboard/apps_list.html +0 -103
  108. data/app/assets/templates/mno_enterprise/dashboard/horizontal_menu.html +0 -85
  109. data/app/assets/templates/mno_enterprise/dashboard/marketplace/index.html +0 -60
  110. data/app/assets/templates/mno_enterprise/dashboard/marketplace/show.html +0 -133
  111. data/app/assets/templates/mno_enterprise/dashboard/menu.html +0 -161
  112. data/app/assets/templates/mno_enterprise/dashboard/organization/arrears.html +0 -37
  113. data/app/assets/templates/mno_enterprise/dashboard/organization/billing.html +0 -37
  114. data/app/assets/templates/mno_enterprise/dashboard/organization/credit-card.html +0 -156
  115. data/app/assets/templates/mno_enterprise/dashboard/organization/index.full.html +0 -181
  116. data/app/assets/templates/mno_enterprise/dashboard/organization/index.html +0 -173
  117. data/app/assets/templates/mno_enterprise/dashboard/organization/invoices.html +0 -27
  118. data/app/assets/templates/mno_enterprise/dashboard/organization/members.html +0 -288
  119. data/app/assets/templates/mno_enterprise/dashboard/organization/settings.html +0 -55
  120. data/app/assets/templates/mno_enterprise/dashboard/teams/index.html +0 -175
  121. data/app/assets/templates/mno_enterprise/dashboard/teams/member-add-modal.html +0 -60
  122. data/app/assets/templates/mno_enterprise/dashboard/teams/member-removal-modal.html +0 -35
  123. data/app/assets/templates/mno_enterprise/dashboard/teams/team-add-modal.html +0 -35
  124. data/app/assets/templates/mno_enterprise/dashboard/teams/team-delete-modal.html +0 -35
  125. data/app/assets/templates/mno_enterprise/dashboard/teams/team-list.html +0 -107
  126. data/app/assets/templates/mno_enterprise/default_template.html +0 -20
  127. data/app/assets/templates/mno_enterprise/maestrano-components/autostop_app.html +0 -42
  128. data/app/assets/templates/mno_enterprise/maestrano-components/currency_widget.html +0 -1
  129. data/app/assets/templates/mno_enterprise/maestrano-components/editable.html +0 -28
  130. data/app/assets/templates/mno_enterprise/maestrano-components/modal-messages/congratulations.html +0 -8
  131. data/app/assets/templates/mno_enterprise/maestrano-components/modal-messages/default.html +0 -1
  132. data/app/assets/templates/mno_enterprise/maestrano-components/modal-messages/information.html +0 -8
  133. data/app/assets/templates/mno_enterprise/maestrano-components/star_wizard.html +0 -254
  134. data/app/assets/templates/mno_enterprise/maestrano-components/upload_spreadsheet.html +0 -191
  135. data/app/assets/templates/mno_enterprise/modals/new-organization-reseller-req.html +0 -35
  136. data/app/assets/templates/mno_enterprise/modals/new-organization.html +0 -35
  137. data/app/assets/templates/mno_enterprise/user-setup/index.html +0 -312
  138. data/app/controllers/mno_enterprise/pages_controller.rb +0 -9
  139. data/app/controllers/mno_enterprise/user_setup_controller.rb +0 -11
  140. data/app/views/layouts/mno_enterprise/_impersonate_header.html.haml +0 -7
  141. data/app/views/layouts/mno_enterprise/application_dashboard.html.haml +0 -22
  142. data/app/views/mno_enterprise/pages/myspace.html.haml +0 -6
  143. data/app/views/mno_enterprise/user_setup/index.html.haml +0 -2
  144. data/config/initializers/ng-performance.rb +0 -3
  145. data/lib/assets/javascripts/impac-angular.js +0 -8719
  146. data/lib/assets/stylesheets/impac-angular.less +0 -2352
  147. data/lib/mno_enterprise/frontend/concerns/README.md +0 -6
  148. data/lib/mno_enterprise/frontend/concerns/controllers/pages_controller.rb +0 -25
  149. data/spec/controllers/mno_enterprise/pages_controller_spec.rb +0 -42
  150. data/spec/controllers/mno_enterprise/user_setup_controller_spec.rb +0 -33
  151. data/spec/routing/mno_enterprise/pages_controller_routing_spec.rb +0 -18
  152. data/spec/routing/mno_enterprise/user_setup_controller_routing_spec.rb +0 -11
@@ -1,5 +0,0 @@
1
-
2
- angular.module('maestrano.filters.app-by-category', []).filter('appByCategory', ->
3
- return (apps, category) ->
4
- _.filter(apps, (app) -> _.contains(app.categories, category))
5
- )
@@ -1,30 +0,0 @@
1
- # in template:
2
- # {{ [amount] | mnoCurrency : [currency] : ([true|false]) }}
3
- # or in js file:
4
- # $filter('mnoCurrency')(amount,currency,[true|false])
5
- #
6
- angular.module('maestrano.filters.currency', []).filter('mnoCurrency', ["$filter", ($filter) ->
7
- (amount, currency, showName=true) ->
8
- if amount?
9
- s = $filter('currency')(amount)
10
-
11
- # official accounting notation: (15) > replaced by: -15
12
- s = s.replace('(','-')
13
- s = s.replace(')','')
14
-
15
- if currency == "EUR"
16
- s = s.replace('$','')
17
- s = s.replace(',', ' ')
18
- s = s.replace('.', ',')
19
- return "#{s} €"
20
- else if currency != "AUD" && currency != "USD"
21
- s = s.replace('$','')
22
-
23
- if showName
24
- return "#{s} #{currency}"
25
- else
26
- return s
27
- else
28
- return ""
29
-
30
- ])
@@ -1,7 +0,0 @@
1
- maestranoFilters = angular.module('maestrano.filters',[
2
- 'maestrano.filters.replace-underscore-with-space',
3
- 'maestrano.filters.titleize',
4
- 'maestrano.filters.truncate',
5
- 'maestrano.filters.currency',
6
- 'maestrano.filters.app-by-category'
7
- ])
@@ -1,4 +0,0 @@
1
- angular.module('maestrano.filters.replace-underscore-with-space', []).filter('replaceUnderscoreWithSpace', [ ->
2
- return (text) ->
3
- return text.replace(/_/g, ' ')
4
- ])
@@ -1,7 +0,0 @@
1
- angular.module('maestrano.filters.titleize', []).filter('titleize', ->
2
- return (s) ->
3
- s = if (s == undefined || s == null) then '' else s
4
- return s.toString().toLowerCase().replace( /\b([a-z])/g, (ch) ->
5
- return ch.toUpperCase()
6
- )
7
- )
@@ -1,24 +0,0 @@
1
- # Usage:
2
- # {{some_text | truncate:100:'...':true}}
3
- #
4
- # Options:
5
- # max (integer) - max length of the text, cut to this number of chars,
6
- # tail (string, default: ' …') - add this string to the input string if the string was cut.
7
- # wordwise (boolean) - if true, cut only by words bounds,
8
- angular.module("maestrano.filters.truncate",[]).filter("truncate", ->
9
- (value, max, tail,wordwise) ->
10
- return "" unless value
11
-
12
- max = parseInt(max, 10)
13
-
14
- return value unless max
15
- return value if value.length <= max
16
-
17
- value = value.substr(0, max)
18
-
19
- if wordwise
20
- lastspace = value.lastIndexOf(" ")
21
- value = value.substr(0, lastspace) unless lastspace is -1
22
-
23
- return value + (tail or "…")
24
- )
@@ -1,15 +0,0 @@
1
- angular.module('maestrano.services.dashboard.app-instance', []).factory('DashboardAppInstance', ['$http','$q', ($http,$q) ->
2
- service = {}
3
-
4
- service.terminate = (id) ->
5
- return $http.delete("/mnoe/jpi/v1/app_instances/#{id}")
6
-
7
- service.restart = (id) ->
8
- return $http.put("/app_instances/#{id}/restart")
9
-
10
- service.updateName = (id,newName) ->
11
- return $http.put("/app_instances/#{id}",{name:newName})
12
-
13
- return service
14
-
15
- ])
@@ -1,83 +0,0 @@
1
- angular.module('maestrano.services.dashboard.apps-document', []).factory('DashboardAppsDocument', ['$http','$q','$window', ($http, $q, $window) ->
2
- # Configuration
3
- service = {}
4
- service.routes = {
5
- basePath: -> "/mnoe/jpi/v1/organizations/#{service.config.id}/app_instances"
6
- plan: {
7
- changePath: (id) -> "/organizations/#{id}/app_change_requests"
8
- }
9
- }
10
-
11
- service.defaultConfig = {
12
- delay: 1000 * 60 # seconds - long polling delay
13
- timestamp: 0
14
- }
15
-
16
- service.config = {
17
- id: null, # The organization id to load
18
- timerId: null, # The current timer id (used for long polling)
19
- $q: null # The current service promise
20
- }
21
-
22
- service.data = {}
23
-
24
- #======================================
25
- # Data Management
26
- #======================================
27
- # Return the id of the currently loaded/loading organization
28
- service.getId = ->
29
- service.config.id
30
-
31
- # Configure the service
32
- service.configure = (opts) ->
33
- # If we change the orga id than we reinitialize the data object
34
- if opts.id then service.data = {}
35
- angular.copy(opts,service.config)
36
- angular.extend(service.config,service.defaultConfig)
37
-
38
- # Load the apps details
39
- service.load = (force = false) ->
40
- self = service
41
- if !self.config.$q? || force
42
- self.config.$q = $http.get("#{self.routes.basePath()}?timestamp=#{self.config.timestamp}").then (success) ->
43
- angular.extend(self.data,success.data.app_instances)
44
- self.config.timestamp = success.data.timestamp
45
-
46
- return self.config.$q
47
-
48
- # Start data auto refresh for the service
49
- service.startAutoRefresh = ->
50
- self = service
51
- unless self.config.timerId?
52
- self.config.timerId = $window.setInterval((-> self.load(true)),self.config.delay)
53
-
54
- # Stop data auto refresh for the service
55
- service.stopAutoRefresh = ->
56
- self = service
57
- if self.config.timerId?
58
- $window.clearInterval(self.config.timerId)
59
- self.config.timerId = null
60
-
61
- # Force the service to reload
62
- service.reload = ->
63
- self = service
64
- self.stopAutoRefresh()
65
- self.config.timestamp = 0
66
- angular.copy({},self.data)
67
- self.load(true).then(self.startAutoRefresh)
68
-
69
- # Setup the service
70
- # A full reload is only performed if the orga id
71
- # passed in the configOpts is different from the one
72
- # currently used
73
- # To force a service reload, use the 'reload' function
74
- service.setup = (configOpts = service.config)->
75
- self = service
76
- if configOpts.id != self.config.id
77
- self.stopAutoRefresh()
78
- self.configure(configOpts)
79
- self.load(true).then(self.startAutoRefresh)
80
-
81
- return service
82
-
83
- ])
@@ -1,27 +0,0 @@
1
- angular.module('maestrano.services.dashboard.user', []).factory('DashboardUser', ['$http','$q', ($http,$q) ->
2
- # Init
3
- service = {}
4
-
5
- service.update = (data) ->
6
- return $http.put("/jpi/v1/current_user",{user:data})
7
-
8
- service.updatePassword = (newPassword,confirmPassword,currentPassword) ->
9
- return $http.put("/auth/users/update_password",{ user: {
10
- password: newPassword,
11
- password_confirmation: confirmPassword,
12
- current_password: currentPassword
13
- } })
14
-
15
- service.deletionRequest = ->
16
- return $http.post("/mnoe/jpi/v1/deletion_requests")
17
-
18
- service.cancelDeletionRequest = (token) ->
19
- return $http.delete("/mnoe/jpi/v1/deletion_requests/#{token}")
20
-
21
- service.resendDeletionRequest = (token) ->
22
- return $http.put("/mnoe/jpi/v1/deletion_requests/#{token}/resend")
23
-
24
-
25
- return service
26
-
27
- ])
@@ -1,318 +0,0 @@
1
- angular.module('maestrano.services.dashboard.organization-svc', []).factory('DhbOrganizationSvc', ['$http','$q','$window','MessageSvc','CurrentUserSvc', ($http,$q,$window,MessageSvc,CurrentUserSvc) ->
2
- # Configuration
3
- service = {}
4
- service.routes = {
5
- createPath: -> "/mnoe/jpi/v1/organizations"
6
- basePath: -> "/mnoe/jpi/v1/organizations/#{service.config.id || ""}"
7
- arrearsSituationsPath: -> "#{service.routes.basePath()}/charge"
8
- loadPath: -> "#{service.routes.basePath()}"
9
- updatePath: -> "#{service.routes.basePath()}"
10
- updateBillingPath: -> "#{service.routes.basePath()}/update_billing"
11
- inviteMembersPath: -> "#{service.routes.basePath()}/invite_members"
12
- updateMemberPath: -> "#{service.routes.basePath()}/update_member"
13
- removeMemberPath: -> "#{service.routes.basePath()}/remove_member"
14
- updateSupportPlanPath: -> "#{service.routes.basePath()}/update_support_plan"
15
- trainingSessionReqPath: -> "#{service.routes.basePath()}/training_session_req"
16
- putMetaDataPath: -> "#{service.routes.basePath()}/meta_data"
17
- }
18
-
19
- service.defaultConfig = {
20
- delay: 2000 * 60 # seconds - long polling delay
21
- }
22
-
23
- service.config = {
24
- id: null, # The organization id to load
25
- timerId: null, # The current timer id (used for long polling)
26
- $q: null # The current service promise
27
- }
28
-
29
- service.data = {}
30
-
31
- #======================================
32
- # Data Management
33
- #======================================
34
- # Return the id of the currently loaded/loading organization
35
- service.getId = ->
36
- service.config.id
37
-
38
- # Configure the service
39
- service.configure = (opts) ->
40
- angular.copy(opts,service.config)
41
- angular.extend(service.config,service.defaultConfig)
42
- return service
43
-
44
- # Load the organization details
45
- # Document structure
46
- # :organization
47
- # :id
48
- # :name
49
- # :soa_enabled(true,false)
50
- # :current_user
51
- # :role('Member','Power User', 'Admin', 'Super Admin')
52
- # :members
53
- # [{ :id, :name, :surname, :email, :role('Invited', 'Member','Power User', 'Admin', 'Super Admin') }]
54
- # :credit_card
55
- # :title
56
- # :first_name
57
- # :last_name
58
- # :number
59
- # :month
60
- # :year
61
- # :country
62
- # :cvv
63
- # :billing_address
64
- # :billing_city
65
- # :billing_postcode
66
- # :billing_country
67
- # :arrears_situations
68
- # [{ :id, :owner_id, :owner_type, :category, :status }]
69
- #
70
- service.load = (force = false) ->
71
- self = service
72
- if !self.config.$q? || force
73
- self.config.$q = $http.get(self.routes.loadPath()).then (success) ->
74
- angular.copy(success.data,self.data)
75
- return self.config.$q
76
-
77
- # Start data auto refresh for the service
78
- service.startAutoRefresh = ->
79
- self = service
80
- unless self.config.timerId?
81
- self.config.timerId = $window.setInterval((-> self.load(true)),self.config.delay)
82
-
83
- # Stop data auto refresh for the service
84
- service.stopAutoRefresh = ->
85
- self = service
86
- if self.config.timerId?
87
- $window.clearInterval(self.config.timerId)
88
- self.config.timerId = null
89
-
90
- # Force the service to reload
91
- service.reload = ->
92
- self.stopAutoRefresh()
93
- self.load(true).then(self.startAutoRefresh)
94
-
95
- # Setup the service
96
- # A full reload is only performed if the orga id
97
- # passed in the configOpts is different from the one
98
- # currently used
99
- # To force a service reload, use the 'reload' function
100
- service.setup = (configOpts = service.config)->
101
- self = service
102
- if configOpts.id != self.config.id
103
- self.stopAutoRefresh()
104
- self.configure(configOpts)
105
- self.load(true).then ->
106
- (self.startAutoRefresh)
107
-
108
- #======================================
109
- # Organization Management
110
- #======================================
111
- service.organization = {}
112
-
113
- # Create a new organization
114
- # e.g. opts: { organization: {name:'bla'}, reseller_req:true }
115
- service.organization.create = (opts) ->
116
- self = service
117
- data = opts
118
- q = $http.post(self.routes.createPath(),data)
119
- q.then (success) ->
120
- CurrentUserSvc.addOrg(success.data.organization)
121
- return q
122
-
123
-
124
- # Edit the details on a given organization
125
- # opts = { name: "SomeName", soa_enabled: true }
126
- service.organization.update = (opts) ->
127
- self = service
128
- data = { organization: opts }
129
- q = $http.put(self.routes.updatePath(),data).then (success)->
130
- angular.copy(success.data.organization,self.data.organization)
131
-
132
- return q
133
-
134
- #======================================
135
- # Billing Management
136
- #======================================
137
- service.billing = {}
138
-
139
- # Update the cc details for this organization
140
- service.billing.update = (opts) ->
141
- self = service
142
- data = { credit_card: opts }
143
- q = $http.put(self.routes.updateBillingPath(),data).then (success)->
144
- angular.copy(success.data.credit_card,self.data.credit_card)
145
-
146
- return q
147
-
148
- #======================================
149
- # Arrears Situations Management
150
- #======================================
151
- service.data.arrears_situations = {}
152
-
153
- service.charge = () ->
154
- self = service
155
- q = $http.put(self.routes.arrearsSituationsPath()).then (response) ->
156
- angular.copy(response.data,self.data.arrears_situations)
157
- return q
158
-
159
- #======================================
160
- # Support Management
161
- #======================================
162
- service.support_plan = {}
163
-
164
- # Update the support plan for this organization
165
- service.support_plan.update = (opts) ->
166
- self = service
167
- data = { support_plan: opts }
168
- q = $http.put(self.routes.updateSupportPlanPath(),data).then (success)->
169
- angular.copy(success.data.organization,self.data.organization)
170
- return q
171
-
172
- # Send an email to the account manager with the training session req
173
- # and consume a training session credit
174
- service.support_plan.training_session_req = (opts) ->
175
- self = service
176
- data = { message: opts }
177
- q = $http.post(self.routes.trainingSessionReqPath(),data).then (success)->
178
- angular.copy(success.data.organization,self.data.organization)
179
- return q
180
-
181
- #======================================
182
- # Member Management
183
- #======================================
184
- service.members = {}
185
- # Accept an array of invites
186
- # [{ email: 'bla@bla.com', role: 'Admin' }]
187
- # Or
188
- # a single email address
189
- # Or
190
- # a an array of email addresses
191
- # Or
192
- # a newline separated list of email addresses
193
- service.members.invite = (invites) ->
194
- self = service
195
- baseList = []
196
- if angular.isString(invites)
197
- baseList = invites.split("\n")
198
- else
199
- baseList = invites
200
-
201
- finalList = []
202
- _.each baseList, (e) ->
203
- if angular.isObject(e)
204
- finalList.push(e)
205
- else
206
- finalList.push({email: e})
207
-
208
- data = { invites: finalList}
209
- q = $http.put(self.routes.inviteMembersPath(), data).then (success)->
210
- angular.copy(success.data.members,self.data.members)
211
-
212
- return q
213
-
214
- # Remove a member from an organization
215
- # The email can either be a user email or an invited
216
- # email
217
- service.members.remove = (opts) ->
218
- self = service
219
- data = { member: { email: opts.email } }
220
- q = $http.put(self.routes.removeMemberPath(),data).then (success)->
221
- angular.copy(success.data.members,self.data.members)
222
-
223
- return q
224
-
225
- # Update the details related to a given member
226
- # opts = { email: 'john@bla.com', role: 'Admin' }
227
- service.members.update = (opts) ->
228
- self = service
229
- data = { member: opts }
230
- q = $http.put(self.routes.updateMemberPath(),data).then (success)->
231
- angular.copy(success.data.members,self.data.members)
232
-
233
- return q
234
-
235
- #======================================
236
- # User Role
237
- #======================================
238
- service.metaData = {}
239
-
240
- # Update the meta_data
241
- service.metaData.checkTask = (name) ->
242
- self = service
243
- data = { name:name, value:true }
244
- q = $http.put(self.routes.putMetaDataPath(),data).then (success)->
245
- self.data.organization.bootstrap_tasks[name] = true
246
-
247
- return q
248
-
249
- #======================================
250
- # User Role
251
- #======================================
252
- service.user = {}
253
-
254
- service.user.isSuperAdmin = ->
255
- service.data.current_user? && service.data.current_user.role == 'Super Admin'
256
-
257
- service.user.isAdmin = ->
258
- service.data.current_user? && service.data.current_user.role == 'Admin'
259
-
260
- service.user.isPowerUser = ->
261
- service.data.current_user? && service.data.current_user.role == 'Power User'
262
-
263
- service.user.isMember = ->
264
- service.data.current_user? && service.data.current_user.role == 'Member'
265
-
266
- service.user.atLeastMember = ->
267
- true
268
-
269
- service.user.atLeastPowerUser = ->
270
- u = service.user
271
- u.isPowerUser() || u.isAdmin() || u.isSuperAdmin()
272
-
273
- service.user.atLeastAdmin = ->
274
- u = service.user
275
- u.isAdmin() || u.isSuperAdmin()
276
-
277
- service.user.atLeastSuperAdmin = ->
278
- service.user.isSuperAdmin()
279
-
280
- #======================================
281
- # Access Management
282
- #======================================
283
- service.can = {}
284
- service.can.read = {}
285
- service.can.create = {}
286
- service.can.update = {}
287
- service.can.destroy = {}
288
-
289
- service.can.read = {
290
- appInstance: (obj = null) -> service.user.atLeastMember()
291
- billing: (obj = null) -> service.user.atLeastSuperAdmin()
292
- member: (obj = null) -> service.user.atLeastMember()
293
- organizationSettings: (obj = null) -> service.user.atLeastSuperAdmin()
294
- }
295
-
296
- service.can.create = {
297
- appInstance: (obj = null) -> service.user.atLeastAdmin()
298
- billing: (obj = null) -> service.user.atLeastSuperAdmin()
299
- member: (obj = null) -> service.user.atLeastAdmin() && (obj == null || obj.role != 'Super Admin' || service.user.isSuperAdmin())
300
- organizationSettings: (obj = null) -> service.user.atLeastSuperAdmin()
301
- }
302
-
303
- service.can.update = {
304
- appInstance: (obj = null) -> service.can.create.appInstance(obj) # call similar permission
305
- billing: (obj = null) -> service.can.create.billing(obj) # call similar permission
306
- member: (obj = null) -> service.can.create.member(obj) # call similar permission
307
- organizationSettings: (obj = null) -> service.can.create.organizationSettings(obj) # call similar permission
308
- }
309
-
310
- service.can.destroy = {
311
- appInstance: (obj = null) -> service.can.create.appInstance(obj) # call similar permission
312
- billing: (obj = null) -> service.can.create.billing(obj) # call similar permission
313
- member: (obj = null) -> service.can.create.member(obj) # call similar permission
314
- organizationSettings: (obj = null) -> service.can.create.organizationSettings(obj) # call similar permission
315
- }
316
-
317
- return service
318
- ])