kms 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/fonts/casper-webfont.eot +0 -0
  5. data/app/assets/fonts/casper-webfont.svg +278 -0
  6. data/app/assets/fonts/casper-webfont.ttf +0 -0
  7. data/app/assets/fonts/casper-webfont.woff +0 -0
  8. data/app/assets/fonts/casper-webfont.woff2 +0 -0
  9. data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
  10. data/app/assets/fonts/glyphicons-halflings-regular.svg +229 -0
  11. data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
  12. data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
  13. data/app/assets/javascripts/kms/application.js +49 -0
  14. data/app/assets/javascripts/kms/application/controllers/assets_controller.coffee +70 -0
  15. data/app/assets/javascripts/kms/application/controllers/help_controller.coffee +12 -0
  16. data/app/assets/javascripts/kms/application/controllers/pages_controller.coffee +95 -0
  17. data/app/assets/javascripts/kms/application/controllers/settings_controller.coffee +21 -0
  18. data/app/assets/javascripts/kms/application/controllers/sidebar_controller.coffee +26 -0
  19. data/app/assets/javascripts/kms/application/controllers/snippets_controller.coffee +44 -0
  20. data/app/assets/javascripts/kms/application/controllers/templates_controller.coffee +46 -0
  21. data/app/assets/javascripts/kms/application/controllers/users_controller.coffee +31 -0
  22. data/app/assets/javascripts/kms/application/module.coffee +24 -0
  23. data/app/assets/javascripts/kms/application/routes.coffee.erb +171 -0
  24. data/app/assets/javascripts/kms/application/services/errors_service.coffee +8 -0
  25. data/app/assets/javascripts/templates/assets/edit.html.slim +10 -0
  26. data/app/assets/javascripts/templates/assets/index.html.slim +31 -0
  27. data/app/assets/javascripts/templates/assets/new.html.slim +16 -0
  28. data/app/assets/javascripts/templates/help.html.slim +172 -0
  29. data/app/assets/javascripts/templates/help/filters.html.slim +51 -0
  30. data/app/assets/javascripts/templates/help/variables.html.slim +96 -0
  31. data/app/assets/javascripts/templates/pages/edit.html.slim +7 -0
  32. data/app/assets/javascripts/templates/pages/form.html.slim +32 -0
  33. data/app/assets/javascripts/templates/pages/index.html.slim +33 -0
  34. data/app/assets/javascripts/templates/pages/new.html.slim +5 -0
  35. data/app/assets/javascripts/templates/settings.html.slim +20 -0
  36. data/app/assets/javascripts/templates/snippets/edit.html.slim +5 -0
  37. data/app/assets/javascripts/templates/snippets/form.html.slim +10 -0
  38. data/app/assets/javascripts/templates/snippets/index.html.slim +22 -0
  39. data/app/assets/javascripts/templates/snippets/new.html.slim +5 -0
  40. data/app/assets/javascripts/templates/templates/edit.html.slim +7 -0
  41. data/app/assets/javascripts/templates/templates/form.html.slim +7 -0
  42. data/app/assets/javascripts/templates/templates/index.html.slim +22 -0
  43. data/app/assets/javascripts/templates/templates/new.html.slim +5 -0
  44. data/app/assets/javascripts/templates/users/form.html.slim +14 -0
  45. data/app/assets/javascripts/templates/users/index.html.slim +21 -0
  46. data/app/assets/javascripts/templates/users/new.html.slim +5 -0
  47. data/app/assets/stylesheets/kms/application.css +57 -0
  48. data/app/assets/stylesheets/kms/custom.css.scss +67 -0
  49. data/app/assets/stylesheets/kms/responsive_dashboard.css.less +9 -0
  50. data/app/controllers/kms/application_controller.rb +24 -0
  51. data/app/controllers/kms/assets_controller.rb +58 -0
  52. data/app/controllers/kms/kms_controller.rb +8 -0
  53. data/app/controllers/kms/pages_controller.rb +67 -0
  54. data/app/controllers/kms/public/pages_controller.rb +27 -0
  55. data/app/controllers/kms/public/search_controller.rb +18 -0
  56. data/app/controllers/kms/resources_controller.rb +9 -0
  57. data/app/controllers/kms/settings_controller.rb +24 -0
  58. data/app/controllers/kms/snippets_controller.rb +37 -0
  59. data/app/controllers/kms/templates_controller.rb +43 -0
  60. data/app/controllers/kms/users_controller.rb +36 -0
  61. data/app/controllers/users/confirmations_controller.rb +28 -0
  62. data/app/controllers/users/omniauth_callbacks_controller.rb +28 -0
  63. data/app/controllers/users/passwords_controller.rb +32 -0
  64. data/app/controllers/users/registrations_controller.rb +70 -0
  65. data/app/controllers/users/sessions_controller.rb +25 -0
  66. data/app/controllers/users/unlocks_controller.rb +28 -0
  67. data/app/helpers/kms/application_helper.rb +4 -0
  68. data/app/models/ability.rb +38 -0
  69. data/app/models/concerns/kms/compile_templates.rb +39 -0
  70. data/app/models/concerns/kms/permalinkable.rb +13 -0
  71. data/app/models/concerns/kms/update_stylesheets_text.rb +20 -0
  72. data/app/models/kms/asset.rb +83 -0
  73. data/app/models/kms/page.rb +61 -0
  74. data/app/models/kms/settings.rb +7 -0
  75. data/app/models/kms/snippet.rb +11 -0
  76. data/app/models/kms/template.rb +11 -0
  77. data/app/models/kms/user.rb +18 -0
  78. data/app/serializers/kms/settings_serializer.rb +5 -0
  79. data/app/serializers/kms/snippet_serializer.rb +5 -0
  80. data/app/services/kms/ability_service.rb +11 -0
  81. data/app/services/kms/externals_registry.rb +11 -0
  82. data/app/services/kms/form_customization_service.rb +14 -0
  83. data/app/services/kms/help_service.rb +13 -0
  84. data/app/services/kms/resource_service.rb +22 -0
  85. data/app/services/kms/search_service.rb +11 -0
  86. data/app/services/kms/settings_service.rb +13 -0
  87. data/app/uploaders/kms/asset_uploader.rb +61 -0
  88. data/app/views/devise/registrations/new.html.erb +21 -0
  89. data/app/views/devise/sessions/new.html.erb +17 -0
  90. data/app/views/devise/shared/_links.html.erb +25 -0
  91. data/app/views/layouts/kms/devise.html.erb +35 -0
  92. data/app/views/layouts/kms/kms.html.erb +139 -0
  93. data/config/initializers/bower_rails.rb +16 -0
  94. data/config/initializers/devise.rb +15 -0
  95. data/config/initializers/externals.rb +42 -0
  96. data/config/initializers/help.rb +1 -0
  97. data/config/initializers/liquor.rb +49 -0
  98. data/config/initializers/resources.rb +5 -0
  99. data/config/locales/devise.en.yml +59 -0
  100. data/config/locales/devise.ru.yml +63 -0
  101. data/config/locales/en.yml +172 -0
  102. data/config/locales/ru.yml +172 -0
  103. data/config/routes.rb +31 -0
  104. data/db/migrate/20141027065341_create_pages.rb +12 -0
  105. data/db/migrate/20141027083603_create_templates.rb +10 -0
  106. data/db/migrate/20141027083633_add_template_id_to_pages.rb +6 -0
  107. data/db/migrate/20141029145253_create_assets.rb +10 -0
  108. data/db/migrate/20141031125758_add_ancestry_to_pages.rb +6 -0
  109. data/db/migrate/20141031140308_devise_create_users.rb +42 -0
  110. data/db/migrate/20141119084306_add_fullpath_to_pages.rb +5 -0
  111. data/db/migrate/20141121112652_add_role_to_users.rb +5 -0
  112. data/db/migrate/20141127073902_add_templatable_fields_to_pages.rb +6 -0
  113. data/db/migrate/20141209132901_add_hidden_to_page.rb +5 -0
  114. data/db/migrate/20150209120632_add_position_to_kms_pages.rb +5 -0
  115. data/db/migrate/20160129100437_create_kms_snippets.rb +11 -0
  116. data/db/migrate/20160712094512_create_kms_settings.rb +9 -0
  117. data/lib/generators/kms/install/install_generator.rb +34 -0
  118. data/lib/generators/kms/install/templates/devise.rb +257 -0
  119. data/lib/generators/kms/install/templates/dragonfly.rb +35 -0
  120. data/lib/kms.rb +6 -0
  121. data/lib/kms/dependencies.rb +15 -0
  122. data/lib/kms/drops/page_drop.rb +24 -0
  123. data/lib/kms/drops/search_item_drop.rb +5 -0
  124. data/lib/kms/engine.rb +65 -0
  125. data/lib/kms/externals/bigdecimal.rb +5 -0
  126. data/lib/kms/externals/request.rb +4 -0
  127. data/lib/kms/functions/assets.rb +40 -0
  128. data/lib/kms/functions/currency.rb +21 -0
  129. data/lib/kms/search_item.rb +28 -0
  130. data/lib/kms/version.rb +3 -0
  131. data/lib/tasks/kms_tasks.rake +4 -0
  132. data/lib/tasks/precompile_hook.rake +42 -0
  133. data/spec/controllers/kms/snippets_controller_spec.rb +74 -0
  134. data/spec/factories/kms_settings.rb +6 -0
  135. data/spec/factories/snippets.rb +10 -0
  136. data/spec/factories/users.rb +7 -0
  137. data/spec/internal/Rakefile +2 -0
  138. data/spec/internal/config/database.yml +7 -0
  139. data/spec/internal/config/initializers/devise.rb +257 -0
  140. data/spec/internal/config/routes.rb +7 -0
  141. data/spec/internal/db/schema.rb +69 -0
  142. data/spec/internal/log/test.log +14998 -0
  143. data/spec/internal/public/favicon.ico +0 -0
  144. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1XyAFYlYI0pK7WAgjR4PgXV6BgU6huJSviWmHetdCRs.cache +1 -0
  145. data/spec/models/kms/setting_spec.rb +7 -0
  146. data/spec/models/kms/snippet_spec.rb +14 -0
  147. data/spec/services/kms/help_service_spec.rb +8 -0
  148. data/spec/spec_helper.rb +27 -0
  149. data/spec/support/controller_macros.rb +11 -0
  150. data/spec/support/request_helpers.rb +7 -0
  151. metadata +521 -0
@@ -0,0 +1,49 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require "codemirror/lib/codemirror"
14
+ //= require "codemirror/mode/xml/xml"
15
+ //= require "codemirror/mode/javascript/javascript"
16
+ //= require "codemirror/mode/css/css"
17
+ //= require "codemirror/mode/htmlmixed/htmlmixed"
18
+ //= require "codemirror/addon/fold/xml-fold"
19
+ //= require "codemirror/addon/edit/closetag"
20
+ //= require "codemirror/addon/display/fullscreen"
21
+ //= require "ng-ckeditor/libs/ckeditor/ckeditor"
22
+ //= require "angular/angular.js"
23
+ //= require "angular-i18n/angular-locale_ru-ru.js"
24
+ //= require "angular-cookies/angular-cookies.js"
25
+ //= require "angular-bootstrap/ui-bootstrap.js"
26
+ //= require "angular-bootstrap/ui-bootstrap-tpls.js"
27
+ //= require "angular-ui-router/release/angular-ui-router.js"
28
+ //= require "lodash/lodash.min"
29
+ //= require "restangular/dist/restangular.min"
30
+ //= require "angular-ui-tree/dist/angular-ui-tree.js"
31
+ //= require "angular-ui-codemirror/ui-codemirror.js"
32
+ //= require "angular-toggle-switch/angular-toggle-switch"
33
+ //= require 'ng-flow/dist/ng-flow-standalone.js'
34
+ //= require "angular-ui-select/dist/select"
35
+ //= require "angular-sanitize/angular-sanitize"
36
+ //= require "ng-ckeditor/ng-ckeditor.min"
37
+ //= require "angular-loading-bar/build/loading-bar.min"
38
+ //= require "angularjs-dropdown-multiselect/dist/angularjs-dropdown-multiselect.min.js"
39
+ //= require "alertify/alertify.min"
40
+ //= require "ng-alertify/ng-alertify"
41
+ //= require "angular-xeditable/dist/js/xeditable"
42
+ //= require "ng-sortable/dist/ng-sortable"
43
+ //= require "kms/application/module"
44
+ //= require "kms/application/routes"
45
+ //= require angular-rails-templates
46
+ //= require_tree ../templates
47
+ //= require_tree ./application/services
48
+ //= require_tree ./application/controllers
49
+ //= require application
@@ -0,0 +1,70 @@
1
+ AssetsController = ($scope, $state, $cookieStore, $cookies, Restangular, $stateParams, Alertify, ErrorsService) ->
2
+ $scope.javascriptEditorOptions =
3
+ lineNumbers: true
4
+ mode: 'javascript'
5
+ extraKeys:
6
+ "F11": (cm)->
7
+ cm.setOption("fullScreen", !cm.getOption("fullScreen"))
8
+ "Esc": (cm)->
9
+ if cm.getOption("fullScreen") then cm.setOption("fullScreen", false)
10
+ $scope.cssEditorOptions =
11
+ lineNumbers: true
12
+ mode: 'css'
13
+ extraKeys:
14
+ "F11": (cm)->
15
+ cm.setOption("fullScreen", !cm.getOption("fullScreen"))
16
+ "Esc": (cm)->
17
+ if cm.getOption("fullScreen") then cm.setOption("fullScreen", false)
18
+
19
+ $scope.store = Restangular.all('assets')
20
+ $scope.store.getList().then (assets)->
21
+ $scope.assets = _.groupBy(assets, 'content_type')
22
+
23
+ if $stateParams.id
24
+ $scope.store.get($stateParams.id).then (asset)->
25
+ $scope.asset = asset
26
+ if /javascript/.test($scope.asset.content_type) or /css/.test($scope.asset.content_type)
27
+ $scope.asset.performing_plain_text = true
28
+ if /javascript/.test($scope.asset.content_type)
29
+ $scope.asset.js = true
30
+ if /css/.test($scope.asset.content_type)
31
+ $scope.asset.css = true
32
+ else
33
+ {}
34
+
35
+ $scope.create = ->
36
+ $scope.store.post($scope.asset).then ->
37
+ $state.go('assets')
38
+ ,(response)->
39
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
40
+
41
+ $scope.update = ($event)->
42
+ $scope.asset.put().then ->
43
+ if $event.target.attributes['data-redirect']
44
+ $state.go('assets')
45
+ ,(response)->
46
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
47
+
48
+ $scope.destroy = (asset)->
49
+ if(confirm('Вы уверены?'))
50
+ asset.remove().then ->
51
+ for content_type, values of $scope.assets
52
+ $scope.assets[content_type] = _.without($scope.assets[content_type], asset)
53
+
54
+ $scope.setHeaders = ->
55
+ 'X-XSRF-TOKEN': $cookies["XSRF-TOKEN"] # call func for getting a cookie
56
+
57
+ $scope.getMode = (asset)->
58
+ if /javascript/.test(asset.content_type)
59
+ "javascript"
60
+ else if /css/.test(asset.content_type)
61
+ "css"
62
+ else
63
+ "htmlmixed"
64
+
65
+ $scope.isImageType = (file)->
66
+ ['jpg', 'jpeg', 'gif','png'].indexOf(file.getType()) >= 0
67
+
68
+
69
+ angular.module('KMS')
70
+ .controller('AssetsController', ['$scope', '$state', '$cookieStore', '$cookies', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', AssetsController])
@@ -0,0 +1,12 @@
1
+ HelpController = ($scope) ->
2
+ $scope.activeTab = 0
3
+
4
+ $scope.isActiveTab = (index)->
5
+ $scope.activeTab == index
6
+
7
+ $scope.setActive = (index)->
8
+ $scope.activeTab = index
9
+
10
+
11
+ angular.module('KMS')
12
+ .controller('HelpController', ['$scope', HelpController])
@@ -0,0 +1,95 @@
1
+ PagesController = ($scope, $state, $cookieStore, Restangular, $stateParams, Alertify, ErrorsService) ->
2
+ $scope.editorOptions =
3
+ #filebrowserBrowseUrl: '/assets/asset/file'
4
+ filebrowserUploadUrl: '/kms/assets/ckeditor'
5
+ entities: false
6
+ $scope.codeMirrorOptions =
7
+ lineNumbers: true
8
+ mode:'htmlmixed'
9
+ autoCloseTags: true
10
+ extraKeys:
11
+ "F11": (cm)->
12
+ cm.setOption("fullScreen", !cm.getOption("fullScreen"))
13
+ "Esc": (cm)->
14
+ if cm.getOption("fullScreen") then cm.setOption("fullScreen", false)
15
+
16
+ Restangular.all('resources').getList().then (templatable_types)->
17
+ $scope.templatable_types = templatable_types
18
+
19
+ Restangular.all('templates').getList().then (templates)->
20
+ $scope.templates = templates
21
+ $scope.store = Restangular.all('pages')
22
+
23
+ Restangular.all('users').customGET('kms_user').then (current_user) ->
24
+ $scope.currentUser = current_user
25
+ $scope.currentUser.admin = $scope.currentUser.role == 'admin'
26
+
27
+ $scope.exceptCurrentPage = (pages) ->
28
+ new_pages = []
29
+ for p in pages
30
+ new_pages.push(p) if p.id != parseInt($stateParams.id)
31
+ new_pages
32
+
33
+ if $stateParams.id
34
+ $scope.store.get($stateParams.id).then (page)->
35
+ $scope.page = page
36
+ else
37
+ $scope.page = {}
38
+
39
+ build_parent_pages = (pages, depth) ->
40
+ str = ""
41
+ i=0
42
+ while i < depth
43
+ str = str+ '-'
44
+ i++
45
+ options = []
46
+ angular.forEach(pages, (value, key) ->
47
+ options.push({id: value.id, title: str+value.title})
48
+ if value.children.length > 0
49
+ options = options.concat(build_parent_pages(value.children, depth+1)))
50
+ return options
51
+
52
+
53
+ $scope.store.getList().then (pages)->
54
+ $scope.pages = pages
55
+ $scope.parentPages = build_parent_pages(pages, 0)
56
+ if $stateParams.id
57
+ $scope.pages = $scope.exceptCurrentPage($scope.pages)
58
+ $scope.parentPages = $scope.exceptCurrentPage($scope.parentPages)
59
+ $scope.page.slug = "index" if $scope.pages.length == 0
60
+ unless $scope.page.parent_id
61
+ index_page = _.select($scope.pages, (p) -> p.slug == 'index')[0]
62
+ $scope.page.parent_id = (if index_page then index_page.id else null)
63
+
64
+
65
+ $scope.create = ->
66
+ $scope.store.post($scope.page).then ->
67
+ $state.go('pages')
68
+ ,(response)->
69
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
70
+
71
+ $scope.update = ($event)->
72
+ $scope.page.put().then ->
73
+ if $event.target.attributes['data-redirect']
74
+ $state.go('pages')
75
+ ,(response)->
76
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
77
+
78
+ $scope.destroy = (page)->
79
+ if(confirm('Вы уверены?'))
80
+ Restangular.restangularizeElement(null, page, 'pages').remove().then ->
81
+ $scope.store.getList().then (pages)->
82
+ $scope.pages = pages
83
+
84
+ $scope.toggle = (scope) ->
85
+ scope.toggle()
86
+
87
+ $scope.treeOptions = {
88
+ dropped: (event) ->
89
+ Restangular.all('pages').customPOST(angular.toJson($scope.pages),'sorting')
90
+ $scope.store.getList().then (pages) ->
91
+ $scope.pages = pages
92
+ }
93
+
94
+ angular.module('KMS')
95
+ .controller('PagesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', PagesController])
@@ -0,0 +1,21 @@
1
+ # TODO: seems the same as HelpController
2
+ SettingsController = ($scope, $state, Restangular, Alertify, ErrorsService) ->
3
+ Restangular.all('settings').customGET().then (settings) ->
4
+ $scope.settings = settings
5
+
6
+ $scope.activeTab = 0
7
+
8
+ $scope.isActiveTab = (index)->
9
+ $scope.activeTab == index
10
+
11
+ $scope.setActive = (index)->
12
+ $scope.activeTab = index
13
+
14
+ $scope.update = ->
15
+ $scope.settings.put().then ->
16
+ $state.go('settings')
17
+ ,(response)->
18
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
19
+
20
+ angular.module('KMS')
21
+ .controller('SettingsController', ['$scope', '$state', 'Restangular', 'Alertify', 'ErrorsService', SettingsController])
@@ -0,0 +1,26 @@
1
+ SidebarController = ($scope, $cookieStore) ->
2
+ #* Sidebar Toggle & Cookie Control
3
+ mobileView = 992
4
+
5
+ $scope.getWidth = -> return window.innerWidth
6
+
7
+ $scope.$watch $scope.getWidth, (newValue, oldValue)->
8
+ if newValue >= mobileView
9
+ if angular.isDefined($cookieStore.get('toggle'))
10
+ if $cookieStore.get('toggle') == false
11
+ $scope.toggle = false
12
+ else
13
+ $scope.toggle = true
14
+ else
15
+ $scope.toggle = true
16
+ else
17
+ $scope.toggle = false
18
+
19
+ $scope.toggleSidebar = ->
20
+ $scope.toggle = ! $scope.toggle
21
+ $cookieStore.put('toggle', $scope.toggle)
22
+
23
+ window.onresize = -> $scope.$apply()
24
+ angular.module('KMS')
25
+ .controller('SidebarController', ['$scope', '$cookieStore', SidebarController])
26
+
@@ -0,0 +1,44 @@
1
+ SnippetsController = ($scope, $state, Restangular, $stateParams, Alertify, ErrorsService) ->
2
+ $scope.editorOptions =
3
+ lineNumbers: true
4
+ mode:'htmlmixed'
5
+ autoCloseTags: true
6
+ extraKeys:
7
+ "F11": (cm)->
8
+ cm.setOption("fullScreen", !cm.getOption("fullScreen"))
9
+ "Esc": (cm)->
10
+ if cm.getOption("fullScreen") then cm.setOption("fullScreen", false)
11
+
12
+ $scope.store = Restangular.all('snippets')
13
+ $scope.store.getList().then (snippets)->
14
+ $scope.snippets = snippets
15
+
16
+ Restangular.all('users').customGET('kms_user').then (current_user) ->
17
+ $scope.currentUser = current_user
18
+ $scope.currentUser.admin = $scope.currentUser.role == 'admin'
19
+
20
+ if $stateParams.id
21
+ $scope.store.get($stateParams.id).then (snippet)->
22
+ $scope.snippet = snippet
23
+ else
24
+ $scope.snippet = {}
25
+
26
+ $scope.create = ->
27
+ $scope.store.post($scope.snippet).then ->
28
+ $state.go('snippets')
29
+ , (response)->
30
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
31
+
32
+ $scope.update = ->
33
+ $scope.snippet.put().then ->
34
+ $state.go('snippets')
35
+ ,(response)->
36
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
37
+
38
+ $scope.destroy = (snippet)->
39
+ if(confirm('Вы уверены?'))
40
+ snippet.remove().then ->
41
+ $scope.snippets = _.without($scope.snippets, snippet)
42
+
43
+ angular.module('KMS')
44
+ .controller('SnippetsController', ['$scope', '$state', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', SnippetsController])
@@ -0,0 +1,46 @@
1
+ TemplatesController = ($scope, $state, $cookieStore, Restangular, $stateParams, Alertify, ErrorsService) ->
2
+ $scope.editorOptions =
3
+ lineNumbers: true
4
+ mode:'htmlmixed'
5
+ autoCloseTags: true
6
+ extraKeys:
7
+ "F11": (cm)->
8
+ cm.setOption("fullScreen", !cm.getOption("fullScreen"))
9
+ "Esc": (cm)->
10
+ if cm.getOption("fullScreen") then cm.setOption("fullScreen", false)
11
+
12
+ $scope.store = Restangular.all('templates')
13
+ $scope.store.getList().then (templates)->
14
+ $scope.templates = templates
15
+
16
+ Restangular.all('users').customGET('kms_user').then (current_user) ->
17
+ $scope.currentUser = current_user
18
+ $scope.currentUser.admin = $scope.currentUser.role == 'admin'
19
+
20
+ if $stateParams.id
21
+ $scope.store.get($stateParams.id).then (template)->
22
+ $scope.template = template
23
+ else
24
+ $scope.template = {}
25
+
26
+ $scope.create = ->
27
+ $scope.store.post($scope.template).then ->
28
+ $state.go('templates')
29
+ , (response)->
30
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
31
+
32
+ $scope.update = ($event)->
33
+ $scope.template.put().then ->
34
+ if $event.target.attributes['data-redirect']
35
+ $state.go('templates')
36
+ ,(response)->
37
+ Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
38
+
39
+ $scope.destroy = (template)->
40
+ if(confirm('Вы уверены?'))
41
+ template.remove().then ->
42
+ $scope.templates = _.without($scope.templates, template)
43
+
44
+
45
+ angular.module('KMS')
46
+ .controller('TemplatesController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', TemplatesController])
@@ -0,0 +1,31 @@
1
+ UsersController = ($scope, $state, $cookieStore, Restangular, $stateParams) ->
2
+ $scope.store = Restangular.all('users')
3
+ $scope.store.getList().then (users)->
4
+ $scope.users = users
5
+
6
+ if $stateParams.id
7
+ $scope.store.get($stateParams.id).then (user)->
8
+ $scope.user = user
9
+ else
10
+ $scope.user = {role: 'content_manager'}
11
+
12
+ $scope.create = ->
13
+ $scope.store.customPOST($scope.user, 'from_kms').then ->
14
+ $state.go('users')
15
+ ,->
16
+ console.log('bug')
17
+
18
+ #$scope.update = ->
19
+ #$scope.user.put().then ->
20
+ #$state.go('users')
21
+ #,->
22
+ #console.log('bug')
23
+
24
+ $scope.destroy = (user)->
25
+ user.remove().then ->
26
+ $scope.users = _.without($scope.users, user)
27
+
28
+
29
+ angular.module('KMS')
30
+ .controller('UsersController', ['$scope', '$state', '$cookieStore', 'Restangular', '$stateParams', UsersController])
31
+
@@ -0,0 +1,24 @@
1
+ angular.module('KMS', ['ui.bootstrap', 'ui.router', 'ngCookies', 'restangular', 'templates', 'ui.tree', 'ui.codemirror', 'flow', 'ui.select', 'ngSanitize', 'ngCkeditor', 'toggle-switch', 'angular-loading-bar', 'angularjs-dropdown-multiselect', 'Alertify', 'xeditable', 'as.sortable'])
2
+
3
+ angular.module('KMS').config ['$httpProvider', '$locationProvider', 'RestangularProvider', 'flowFactoryProvider', 'cfpLoadingBarProvider', ($httpProvider, $locationProvider, RestangularProvider, flowFactoryProvider, cfpLoadingBarProvider) ->
4
+ cfpLoadingBarProvider.includeSpinner = false
5
+ $locationProvider.html5Mode(true)
6
+ $httpProvider.defaults.withCredentials = true
7
+
8
+ RestangularProvider.setBaseUrl('/kms')
9
+ RestangularProvider.setRequestSuffix(".json")
10
+
11
+ flowFactoryProvider.defaults =
12
+ target: '/kms/assets.json'
13
+ permanentErrors: [404, 500, 501]
14
+ maxChunkRetries: 1
15
+ chunkSize: 50*1024*1024
16
+ chunkRetryInterval: 5000
17
+ simultaneousUploads: 4
18
+ testChunks: false
19
+ fileParameterName: "asset[file]"
20
+ ]
21
+ .run ['$http', '$cookies', 'editableOptions', ($http, $cookies, editableOptions) ->
22
+ $http.defaults.headers.common['X-XSRF-TOKEN'] = $cookies['XSRF-TOKEN']
23
+ editableOptions.theme = 'bs3'
24
+ ]
@@ -0,0 +1,171 @@
1
+ 'use strict'
2
+
3
+ angular.module('KMS').config ['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) ->
4
+
5
+ $urlRouterProvider.when('/', '/kms/pages')
6
+ # For unmatched routes
7
+ $urlRouterProvider.otherwise('/')
8
+
9
+ # Application routes
10
+ $stateProvider
11
+ .state('help', {
12
+ url: '/kms/help',
13
+ views:
14
+ "header":
15
+ template: "<%= I18n.t(:help) %>"
16
+ "@":
17
+ controller: 'HelpController',
18
+ controllerAs: 'help',
19
+ templateUrl: 'help.html'
20
+ })
21
+ .state('settings', {
22
+ url: '/kms/settings',
23
+ views:
24
+ "header":
25
+ template: "<%= I18n.t(:settings) %>"
26
+ "@":
27
+ controller: 'SettingsController',
28
+ controllerAs: 'settings',
29
+ templateUrl: 'settings.html'
30
+ })
31
+ .state('pages', {
32
+ url: '/kms/pages',
33
+ views:
34
+ "header":
35
+ template: "<%= Kms::Page.model_name.human(count: 1.1) %>"
36
+ "@":
37
+ controller: 'PagesController',
38
+ controllerAs: 'pages',
39
+ templateUrl: 'pages/index.html',
40
+ })
41
+ .state('pages.new', {
42
+ url: '/new',
43
+ views:
44
+ "header@":
45
+ template: "<%= I18n.t(:new_page) %>"
46
+ "@":
47
+ controller: 'PagesController',
48
+ controllerAs: 'pages',
49
+ templateUrl: 'pages/new.html',
50
+ })
51
+ .state('pages.edit', {
52
+ url: '/:id/edit',
53
+ views:
54
+ "header@":
55
+ template: "<%= I18n.t(:edit_page) %>"
56
+ "@":
57
+ controller: 'PagesController',
58
+ controllerAs: 'pages',
59
+ templateUrl: 'pages/edit.html',
60
+ })
61
+ .state('templates', {
62
+ url: '/kms/templates',
63
+ views:
64
+ "header":
65
+ template: "<%= Kms::Template.model_name.human(count: 1.1) %>"
66
+ "@":
67
+ controller: 'TemplatesController',
68
+ controllerAs: 'templates',
69
+ templateUrl: 'templates/index.html'
70
+ })
71
+ .state('templates.new', {
72
+ url: '/new',
73
+ views:
74
+ "header@":
75
+ template: "<%= I18n.t(:new_template) %>"
76
+ "@":
77
+ controller: 'TemplatesController',
78
+ controllerAs: 'templates',
79
+ templateUrl: 'templates/new.html',
80
+ })
81
+ .state('templates.edit', {
82
+ url: '/:id/edit',
83
+ views:
84
+ "header@":
85
+ template: "<%= I18n.t(:edit_template) %>"
86
+ "@":
87
+ controller: 'TemplatesController',
88
+ controllerAs: 'templates',
89
+ templateUrl: 'templates/edit.html',
90
+ })
91
+ .state('assets', {
92
+ url: '/kms/assets',
93
+ views:
94
+ "header":
95
+ template: "<%= Kms::Asset.model_name.human(count: 1.1) %>"
96
+ "@":
97
+ controller: 'AssetsController',
98
+ controllerAs: 'assets',
99
+ templateUrl: 'assets/index.html'
100
+ })
101
+ .state('assets.new', {
102
+ url: '/new',
103
+ views:
104
+ "header@":
105
+ template: "<%= I18n.t(:new_asset) %>"
106
+ "@":
107
+ controller: 'AssetsController',
108
+ controllerAs: 'assets',
109
+ templateUrl: 'assets/new.html',
110
+ })
111
+ .state('assets.edit', {
112
+ url: '/:id/edit',
113
+ views:
114
+ "header@":
115
+ template: "<%= I18n.t(:edit_asset) %>"
116
+ "@":
117
+ controller: 'AssetsController',
118
+ controllerAs: 'assets',
119
+ templateUrl: 'assets/edit.html',
120
+ })
121
+ .state('users', {
122
+ url: '/kms/users',
123
+ views:
124
+ "header":
125
+ template: "<%= Kms::User.model_name.human(count: 1.1) %>"
126
+ "@":
127
+ controller: 'UsersController',
128
+ controllerAs: 'users',
129
+ templateUrl: 'users/index.html'
130
+ })
131
+ .state('users.new', {
132
+ url: '/new',
133
+ views:
134
+ "header@":
135
+ template: "<%= I18n.t(:new_user) %>"
136
+ "@":
137
+ controller: 'UsersController',
138
+ controllerAs: 'users',
139
+ templateUrl: 'users/new.html',
140
+ })
141
+ .state('snippets', {
142
+ url: '/kms/snippets',
143
+ views:
144
+ "header":
145
+ template: "<%= Kms::Snippet.model_name.human(count: 1.1) %>"
146
+ "@":
147
+ controller: 'SnippetsController',
148
+ controllerAs: 'snippets',
149
+ templateUrl: 'snippets/index.html'
150
+ })
151
+ .state('snippets.new', {
152
+ url: '/new',
153
+ views:
154
+ "header@":
155
+ template: "<%= I18n.t(:new_snippet) %>"
156
+ "@":
157
+ controller: 'SnippetsController',
158
+ controllerAs: 'snippets',
159
+ templateUrl: 'snippets/new.html',
160
+ })
161
+ .state('snippets.edit', {
162
+ url: '/:id/edit',
163
+ views:
164
+ "header@":
165
+ template: "<%= I18n.t(:edit_snippet) %>"
166
+ "@":
167
+ controller: 'SnippetsController',
168
+ controllerAs: 'snippets',
169
+ templateUrl: 'snippets/edit.html',
170
+ })
171
+ ]