Skip to content

Commit 3e77861

Browse files
committed
make it public
0 parents  commit 3e77861

File tree

115 files changed

+1976
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1976
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.bundle/
2+
log/*.log
3+
pkg/
4+
test/dummy/db/*.sqlite3
5+
test/dummy/db/*.sqlite3-journal
6+
test/dummy/log/*.log
7+
test/dummy/tmp/
8+
test/dummy/.sass-cache
9+
*.swp
10+
*.swo
11+
*~

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Version 0.6.0 2016-10-01
2+
3+
* [changed] allow to edit Entry slug, but autogenerate on creation
4+
* [added] English translations
5+
6+
## Version 0.5.0 2016-02-09
7+
8+
* [fixed] fix saving unchecked checkbox
9+
* [fixed] element updating not working when some field are empty
10+
* [changed] allow to pass File object when storing values for File Fields
11+
* [changed] allow more file types for file fields - doc, xls, pdf, mp4, webm (previously only images allowed)
12+
* [changed] alert about errors using Alertify
13+
* [added] add ability to order model entries - using `order` method
14+
* [added] register model in ModelDrop after creation - no need in app restart
15+
* [added] Collection name method added - `item.model_collection_name`
16+
* [added] expose entry id field in liquor
17+
* [added] add confirmation before Model deleting
18+
* [added] added BelongsTo field for Models (similar to Rails belongs_to)
19+
* [added] support searching/filtering model entries with 'find_all_by', 'find_by'

Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
# Declare your gem's dependencies in kms_models.gemspec.
4+
# Bundler will treat runtime dependencies like base dependencies, and
5+
# development dependencies will be added by default to the :development group.
6+
gemspec
7+
8+
# Declare any dependencies that are still in development here instead of in
9+
# your gemspec. These might include edge Rails or gems from your path or
10+
# Git. Remember to move these dependencies to your gemspec before releasing
11+
# your gem to rubygems.org.
12+
13+
# To use a debugger
14+
# gem 'byebug', group: [:development, :test]

MIT-LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2015 Igor Petrov
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## KmsModels
2+
3+
Requires at least PostgreSQL 9.2 because of JSON column type
4+
5+
## Installation
6+
7+
1. Add to Gemfile
8+
9+
gem "kms_models"
10+
# or for edge version:
11+
gem "kms_models", github: "webgradus/kms_models"
12+
13+
2. Run generator:
14+
15+
rails g kms_models:install
16+
17+
3. Copy migrations:
18+
19+
rake kms_models:install:migrations
20+
21+
4. Migrate:
22+
23+
bundle exec rake db:migrate
24+
25+
5. Recompile assets:
26+
27+
bundle exec rake assets:precompile
28+
29+
6. Restart KMS instance

Rakefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
begin
2+
require 'bundler/setup'
3+
rescue LoadError
4+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5+
end
6+
7+
require 'rdoc/task'
8+
9+
RDoc::Task.new(:rdoc) do |rdoc|
10+
rdoc.rdoc_dir = 'rdoc'
11+
rdoc.title = 'KmsModels'
12+
rdoc.options << '--line-numbers'
13+
rdoc.rdoc_files.include('README.rdoc')
14+
rdoc.rdoc_files.include('lib/**/*.rb')
15+
end
16+
17+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18+
load 'rails/tasks/engine.rake'
19+
20+
21+
load 'rails/tasks/statistics.rake'
22+
23+
24+
25+
Bundler::GemHelper.install_tasks
26+
27+
require 'rake/testtask'
28+
29+
Rake::TestTask.new(:test) do |t|
30+
t.libs << 'lib'
31+
t.libs << 'test'
32+
t.pattern = 'test/**/*_test.rb'
33+
t.verbose = false
34+
end
35+
36+
37+
task default: :test

app/assets/images/kms_models/.keep

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/javascripts directory 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 "kms_models/application/routes"
14+
//= require_tree "../templates"
15+
//= require_tree "./application/controllers"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
EntriesController = ($scope, $state, Restangular, $stateParams, Alertify, ErrorsService) ->
2+
$scope.modelStore = Restangular.all('models')
3+
$scope.store = Restangular.one("models", $stateParams.modelId).all("entries")
4+
$scope.editorOptions =
5+
filebrowserUploadUrl: '/kms/assets/ckeditor'
6+
7+
#Restangular.all('users').customGET('kms_user').then (current_user) ->
8+
#$scope.currentUser = current_user
9+
#$scope.currentUser.admin = $scope.currentUser.role == 'admin'
10+
11+
$scope.entriesSortableOptions =
12+
orderChanged: (event)->
13+
for entry, index in event.dest.sortableScope.modelValue
14+
entry_copy =
15+
id: entry.id
16+
position: index
17+
Restangular.restangularizeElement($scope.model, entry_copy, 'entries').put()
18+
19+
$scope.modelStore.get($stateParams.modelId).then (model)->
20+
$scope.model = model
21+
fields = $scope.getAssociationFields(model)
22+
_.each fields, (field)->
23+
$scope[field.liquor_name] = [] # pre-init
24+
Restangular.one("models", field.class_name).all("entries").getList().then (entries)->
25+
$scope[field.liquor_name] = entries
26+
$scope.initAssociationField(field)
27+
28+
$scope.initAssociationField = (field)->
29+
if field.type == 'Kms::HasManyField'
30+
$scope.entry.values[field.liquor_name] = _.filter $scope[field.liquor_name], (element)->
31+
_.contains $scope.entry.values[field.liquor_name], element.id.toString()
32+
else
33+
$scope.entry.values[field.liquor_name] = _.find $scope[field.liquor_name], (element)->
34+
$scope.entry.values[field.liquor_name] == element.id.toString()
35+
36+
$scope.store.getList().then (entries)->
37+
$scope.entries = entries
38+
39+
if $stateParams.id
40+
$scope.store.get($stateParams.id).then (entry)->
41+
$scope.entry = entry
42+
else
43+
$scope.entry = {values: {}}
44+
45+
$scope.getAssociationFields = (model)->
46+
_.filter model.fields, (field) -> field.type == 'Kms::HasManyField' or field.type == 'Kms::BelongsToField'
47+
48+
$scope.getFieldTemplateName = (field)->
49+
typeSplitted = field.type.split '::'
50+
_.snakeCase(typeSplitted[typeSplitted.length - 1])
51+
52+
$scope.create = ->
53+
fd = new FormData
54+
if $scope.entry.slug
55+
fd.append("entry[slug]", $scope.entry.slug)
56+
for key, value of $scope.entry.values
57+
fd.append("entry[values][#{key}]", value || '')
58+
$scope.store.withHttpConfig({ transformRequest: angular.identity }).post(fd, null, {"Content-Type": undefined}).then ->
59+
$state.go('models.entries', modelId: $scope.model.id)
60+
,(response)->
61+
Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
62+
63+
$scope.update = ->
64+
fd = new FormData
65+
if $scope.entry.slug
66+
fd.append("entry[slug]", $scope.entry.slug)
67+
for key, value of $scope.entry.values
68+
continue if value == undefined
69+
if value
70+
if value.constructor.name == 'Array'
71+
for element in value
72+
id = if element.constructor.name == 'Object' then element.id else element
73+
fd.append("entry[values][#{key}][]", id)
74+
else if value.constructor.name != 'Object'
75+
fd.append("entry[values][#{key}]", value || '')
76+
else
77+
fd.append("entry[values][#{key}]", value || '')
78+
$scope.entry.withHttpConfig({ transformRequest: angular.identity }).post('', fd, '', {"Content-Type": undefined}).then ->
79+
$state.go('models.entries', modelId: $scope.model.id)
80+
,(response)->
81+
Alertify.error(ErrorsService.prepareErrorsString(response.data.errors))
82+
83+
$scope.destroy = (entry)->
84+
if(confirm('Вы уверены?'))
85+
entry.remove().then ->
86+
$scope.entries = _.without($scope.entries, entry)
87+
88+
89+
90+
angular.module('KMS')
91+
.controller('EntriesController', ['$scope', '$state', 'Restangular', '$stateParams', 'Alertify', 'ErrorsService', EntriesController])
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FieldsController = ($scope, $state, Restangular, $stateParams) ->
2+
$scope.types = [
3+
{ id: 'Kms::StringField', name: "<%= I18n.t("field_types.string") %>"},
4+
{ id: 'Kms::TextField', name: "<%= I18n.t("field_types.text") %>"},
5+
{ id: 'Kms::CheckboxField', name: "<%= I18n.t("field_types.checkbox") %>"},
6+
{ id: 'Kms::FileField', name: "<%= I18n.t("field_types.file") %>"},
7+
{ id: 'Kms::HasManyField', name: "<%= I18n.t("field_types.has_many") %>"},
8+
{ id: 'Kms::BelongsToField', name: "<%= I18n.t("field_types.belongs_to") %>"},
9+
]
10+
11+
Restangular.all('resources').getList().then (templatable_types)->
12+
$scope.templatable_types = templatable_types
13+
14+
Restangular.all('users').customGET('kms_user').then (current_user) ->
15+
$scope.currentUser = current_user
16+
$scope.currentUser.admin = $scope.currentUser.role == 'admin'
17+
18+
$scope.field = {}
19+
20+
$scope.formatType = (field)->
21+
fieldType = _.find $scope.types, (type) -> type.id == field.type
22+
if $scope.isAssociationField(field) then "#{fieldType.name} (#{$scope.getDisplayableTemplatableType(field)})" else fieldType.name
23+
24+
$scope.getDisplayableTemplatableType = (field)->
25+
templatable_type = _.find $scope.templatable_types, (templatable_type) -> templatable_type.type == field.class_name
26+
templatable_type.title
27+
28+
$scope.isAssociationField = (field)->
29+
field.type == 'Kms::HasManyField' or field.type == 'Kms::BelongsToField'
30+
31+
$scope.addField = ->
32+
if $scope.field.name and $scope.field.type
33+
$scope.model.fields.push($scope.field)
34+
$scope.field = {}
35+
36+
$scope.removeField = (field)->
37+
field['_destroy'] = '1' # for rails deletion
38+
#$scope.model.fields = _.without($scope.model.fields, field)
39+
40+
41+
angular.module('KMS')
42+
.controller('FieldsController', ['$scope', '$state', 'Restangular', '$stateParams', FieldsController])
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ModelsController = ($scope, $state, Restangular, $stateParams) ->
2+
$scope.store = Restangular.all('models')
3+
4+
Restangular.all('users').customGET('kms_user').then (current_user) ->
5+
$scope.currentUser = current_user
6+
$scope.currentUser.admin = $scope.currentUser.role == 'admin'
7+
8+
$scope.store.getList().then (models)->
9+
$scope.models = models
10+
11+
if $stateParams.id
12+
$scope.store.get($stateParams.id).then (model)->
13+
$scope.model = model
14+
else
15+
$scope.model = {fields: []}
16+
17+
$scope.$watchCollection 'model.fields', (newFields, oldFields) ->
18+
if newFields and newFields.length > 0 and oldFields and oldFields.length == 0
19+
$scope.model.label_field =newFields[0].liquor_name
20+
21+
$scope.create = ->
22+
$scope.store.post($scope.model).then ->
23+
# for adding to Menu - better to render resources via js
24+
window.location.reload()
25+
#$state.go('models')
26+
,->
27+
console.log('bug')
28+
29+
$scope.update = ->
30+
$scope.model.put().then ->
31+
$state.go('models')
32+
,->
33+
console.log('bug')
34+
35+
$scope.destroy = (model)->
36+
if confirm('Вы уверены?')
37+
model.remove().then ->
38+
window.location.reload()
39+
40+
41+
angular.module('KMS')
42+
.controller('ModelsController', ['$scope', '$state', 'Restangular', '$stateParams', ModelsController])
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict'
2+
3+
angular.module('KMS').config ['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) ->
4+
5+
# Application routes
6+
$stateProvider
7+
.state('models', {
8+
url: '/kms/models',
9+
views:
10+
"header":
11+
template: "<%= Kms::Model.model_name.human(count: 1.1) %>"
12+
"@":
13+
controller: 'ModelsController',
14+
controllerAs: 'models',
15+
templateUrl: 'models/index.html',
16+
})
17+
.state('models.new', {
18+
url: '/new',
19+
views:
20+
"header@":
21+
template: "<%= I18n.t(:new_model) %>"
22+
"@":
23+
controller: 'ModelsController',
24+
controllerAs: 'models',
25+
templateUrl: 'models/new.html',
26+
})
27+
.state('models.edit', {
28+
url: '/:id/edit',
29+
views:
30+
"header@":
31+
template: "<%= I18n.t(:edit_model) %>"
32+
"@":
33+
controller: 'ModelsController',
34+
controllerAs: 'models',
35+
templateUrl: 'models/edit.html',
36+
})
37+
.state('models.entries', {
38+
url: '/:modelId/entries',
39+
views:
40+
"header@":
41+
template: "<%= Kms::Entry.model_name.human(count: 1.1) %>"
42+
"@":
43+
controller: 'EntriesController',
44+
controllerAs: 'entries',
45+
templateUrl: 'entries/index.html',
46+
})
47+
.state('models.entries.new', {
48+
url: '/new',
49+
views:
50+
"header@":
51+
template: "<%= I18n.t(:new_entry) %>"
52+
"@":
53+
controller: 'EntriesController',
54+
controllerAs: 'entries',
55+
templateUrl: 'entries/new.html'
56+
})
57+
.state('models.entries.edit', {
58+
url: '/:id/edit',
59+
views:
60+
"header@":
61+
template: "<%= I18n.t(:edit_entry) %>"
62+
"@":
63+
controller: 'EntriesController',
64+
controllerAs: 'entries',
65+
templateUrl: 'entries/edit.html'
66+
})
67+
]

0 commit comments

Comments
 (0)