blacksand 2.2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +27 -0
- data/app/assets/javascripts/blacksand/dashboard/navigations.form.js.erb +34 -0
- data/app/assets/javascripts/blacksand/dashboard/navigations.index.js +18 -0
- data/app/assets/javascripts/blacksand/dashboard/pages.form.js.erb +69 -0
- data/app/assets/javascripts/blacksand/dashboard/pages.index.js +17 -0
- data/app/assets/javascripts/blacksand/dashboard.js +14 -0
- data/app/assets/javascripts/blacksand/ie.js +2 -0
- data/app/assets/javascripts/bootstrap-datepicker.zh-CN.js +20 -0
- data/app/assets/stylesheets/blacksand/dashboard.scss +26 -0
- data/app/controllers/blacksand/dashboard/base_controller.rb +35 -0
- data/app/controllers/blacksand/dashboard/navigations_controller.rb +88 -0
- data/app/controllers/blacksand/dashboard/pages_controller.rb +176 -0
- data/app/controllers/blacksand/dashboard/prototypes_controller.rb +12 -0
- data/app/controllers/blacksand/dashboard/templates_controller.rb +8 -0
- data/app/controllers/blacksand/dashboard/users_controller.rb +78 -0
- data/app/controllers/blacksand_front/pages_controller.rb +17 -0
- data/app/helpers/blacksand/application_helper.rb +42 -0
- data/app/helpers/blacksand/page_helper.rb +11 -0
- data/app/helpers/blacksand_front/pages_helper.rb +20 -0
- data/app/models/blacksand/field.rb +35 -0
- data/app/models/blacksand/navigation.rb +24 -0
- data/app/models/blacksand/page.rb +194 -0
- data/app/models/blacksand/picture.rb +7 -0
- data/app/models/blacksand/property/as_array.rb +5 -0
- data/app/models/blacksand/property/file.rb +5 -0
- data/app/models/blacksand/property/gallery.rb +7 -0
- data/app/models/blacksand/property/slide.rb +5 -0
- data/app/models/blacksand/property.rb +76 -0
- data/app/models/blacksand/prototype.rb +11 -0
- data/app/models/blacksand/template.rb +9 -0
- data/app/models/kindeditor/asset.rb +14 -0
- data/app/models/kindeditor/file.rb +3 -0
- data/app/models/kindeditor/flash.rb +3 -0
- data/app/models/kindeditor/image.rb +3 -0
- data/app/models/kindeditor/media.rb +3 -0
- data/app/uploaders/blacksand/base_uploader.rb +16 -0
- data/app/uploaders/blacksand/file_uploader.rb +4 -0
- data/app/uploaders/blacksand/image_uploader.rb +78 -0
- data/app/uploaders/blacksand/slide_image_uploader.rb +66 -0
- data/app/views/blacksand/dashboard/navigations/_form.html.erb +23 -0
- data/app/views/blacksand/dashboard/navigations/edit.html.erb +3 -0
- data/app/views/blacksand/dashboard/navigations/index.html.erb +40 -0
- data/app/views/blacksand/dashboard/navigations/index.json.jbuilder +4 -0
- data/app/views/blacksand/dashboard/navigations/new.html.erb +3 -0
- data/app/views/blacksand/dashboard/navigations/reorder.js.erb +1 -0
- data/app/views/blacksand/dashboard/navigations/show.html.erb +4 -0
- data/app/views/blacksand/dashboard/navigations/show.json.jbuilder +1 -0
- data/app/views/blacksand/dashboard/pages/_fields.html.erb +89 -0
- data/app/views/blacksand/dashboard/pages/_form.html.erb +26 -0
- data/app/views/blacksand/dashboard/pages/_manage_list.html.erb +123 -0
- data/app/views/blacksand/dashboard/pages/_picture_fields.html.erb +18 -0
- data/app/views/blacksand/dashboard/pages/children_partial.js.erb +14 -0
- data/app/views/blacksand/dashboard/pages/edit.html.erb +20 -0
- data/app/views/blacksand/dashboard/pages/index.html.erb +27 -0
- data/app/views/blacksand/dashboard/pages/new.html.erb +20 -0
- data/app/views/blacksand/dashboard/pages/onchange_render.js.erb +14 -0
- data/app/views/blacksand/dashboard/pages/search.json.jbuilder +7 -0
- data/app/views/blacksand/dashboard/pages/show.html.erb +34 -0
- data/app/views/blacksand/dashboard/prototypes/index.html.erb +15 -0
- data/app/views/blacksand/dashboard/prototypes/show.html.erb +31 -0
- data/app/views/blacksand/dashboard/templates/index.html.erb +17 -0
- data/app/views/blacksand/dashboard/users/_form.html.erb +40 -0
- data/app/views/blacksand/dashboard/users/edit.html.erb +47 -0
- data/app/views/blacksand/dashboard/users/index.html.erb +37 -0
- data/app/views/blacksand/dashboard/users/index.json.jbuilder +4 -0
- data/app/views/blacksand/dashboard/users/new.html.erb +4 -0
- data/app/views/blacksand/dashboard/users/show.html.erb +2 -0
- data/app/views/blacksand/dashboard/users/show.json.jbuilder +1 -0
- data/app/views/layouts/blacksand/_navbar.html.erb +42 -0
- data/app/views/layouts/blacksand/dashboard.html.erb +33 -0
- data/config/locales/kaminari.zh-CN.yml +17 -0
- data/config/locales/nestable.zh-CN.yml +14 -0
- data/config/locales/zh-CN.yml +69 -0
- data/config/routes.rb +31 -0
- data/db/migrate/20151112055035_create_templates.rb +10 -0
- data/db/migrate/20151112055425_create_prototypes.rb +9 -0
- data/db/migrate/20151112055438_create_fields.rb +14 -0
- data/db/migrate/20151112055821_create_pages.rb +15 -0
- data/db/migrate/20151112060015_create_properties.rb +15 -0
- data/db/migrate/20151112060605_create_navigations.rb +13 -0
- data/db/migrate/20151209022305_create_kindeditor_assets.rb +17 -0
- data/db/migrate/20160513080702_create_pictures.rb +12 -0
- data/db/migrate/20170104014706_add_values_to_properties.rb +5 -0
- data/db/migrate/20170310092041_add_owner_type_to_kindeditor_asset.rb +5 -0
- data/db/migrate/20170322021913_add_options_to_template_and_prototype.rb +6 -0
- data/lib/blacksand/caching_pages.rb +16 -0
- data/lib/blacksand/cancancan.rb +19 -0
- data/lib/blacksand/controller_helper.rb +21 -0
- data/lib/blacksand/engine.rb +69 -0
- data/lib/blacksand/expire_pages.rb +21 -0
- data/lib/blacksand/my_json_type.rb +61 -0
- data/lib/blacksand/routing.rb +11 -0
- data/lib/blacksand/version.rb +3 -0
- data/lib/blacksand.rb +53 -0
- data/lib/generators/blacksand/install_generator.rb +30 -0
- data/lib/generators/blacksand/new_site_generator.rb +28 -0
- data/lib/tasks/blacksand_tasks.rake +72 -0
- data/lib/tasks/carrierwave_storage_migrate_to_qiniu.rake +25 -0
- metadata +541 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 85cea919a0385fa796cd17228e35f52c161c26d3
|
|
4
|
+
data.tar.gz: b1ccce8a35f8f38e7bec370076514114039c0bf7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4d5b6c433265729b8c4cfb79ca62bf7ae82ea49c0ae5f9dc74fd31a50132c8e08d6cd5c57a4d2df38da8070fb9e63b4e434ce1c3fb876df5fb76b051b4e87048
|
|
7
|
+
data.tar.gz: 9ef5b174ade89dae9315047d766b8df215e4eb91701922f1f99be49af6dcf98cbadcc516310de33a04ea8e92b292bc5d1725e70258f0ca6970e839022e6610c6
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2016 bastengao
|
|
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.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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 = 'Blacksand'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
19
|
+
load 'rails/tasks/engine.rake'
|
|
20
|
+
|
|
21
|
+
load 'rails/tasks/statistics.rake'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'bundler/gem_tasks'
|
|
26
|
+
# Bundler::GemHelper.install_tasks
|
|
27
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
$(function(){
|
|
2
|
+
if($('#navigations-new, #navigations-edit').length <= 0){
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
$('#navigation_page_id').select2({
|
|
7
|
+
language: 'zh-CN',
|
|
8
|
+
placeholder: '无',
|
|
9
|
+
allowClear: true,
|
|
10
|
+
ajax: {
|
|
11
|
+
url: '<%= Blacksand::Engine.routes.url_helpers.search_pages_path(format: :json) %>',
|
|
12
|
+
dataType: 'json',
|
|
13
|
+
delay: 250,
|
|
14
|
+
data: function (params) {
|
|
15
|
+
return {
|
|
16
|
+
'q[title_cont]': params.term, // search term
|
|
17
|
+
page: params.page
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
processResults: function (data, params) {
|
|
21
|
+
params.page = params.page || 1;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
results: data.pages,
|
|
25
|
+
pagination: {
|
|
26
|
+
more: params.page < data.total_pages
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
cache: false
|
|
31
|
+
},
|
|
32
|
+
minimumInputLength: 1
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
$(function(){
|
|
2
|
+
if($('#navigations-index').length <= 0){
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
dragula([$('#nav-table tbody')[0]]).on('drop', function(){
|
|
7
|
+
console.log('drop')
|
|
8
|
+
|
|
9
|
+
// 保存顺序
|
|
10
|
+
var newOrders = $('#nav-table tbody').children().map(function(){
|
|
11
|
+
return $(this).data('navigation-id')
|
|
12
|
+
})
|
|
13
|
+
.get();
|
|
14
|
+
|
|
15
|
+
var update_url = $('#nav-table tbody').data('update-url');
|
|
16
|
+
$.post(update_url, {navigations: newOrders})
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
$(function(){
|
|
2
|
+
if($('#pages-new, #pages-edit').length <= 0){
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function initSelect2() {
|
|
7
|
+
$('#page_parent_id, select[data-provide="page-select2"]').select2({
|
|
8
|
+
language: 'zh-CN',
|
|
9
|
+
placeholder: '无',
|
|
10
|
+
allowClear: true,
|
|
11
|
+
ajax: {
|
|
12
|
+
url: '<%= Blacksand::Engine.routes.url_helpers.search_pages_path(format: :json) %>',
|
|
13
|
+
dataType: 'json',
|
|
14
|
+
delay: 250,
|
|
15
|
+
data: function (params) {
|
|
16
|
+
return {
|
|
17
|
+
'q[title_cont]': params.term, // search term
|
|
18
|
+
page: params.page
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
processResults: function (data, params) {
|
|
22
|
+
params.page = params.page || 1;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
results: data.pages,
|
|
26
|
+
pagination: {
|
|
27
|
+
more: params.page < data.total_pages
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
cache: false
|
|
32
|
+
},
|
|
33
|
+
minimumInputLength: 1
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 暴露给 onchange_render.js.erb
|
|
38
|
+
window.initSelect2 = initSelect2;
|
|
39
|
+
|
|
40
|
+
initSelect2();
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// add text input for array property
|
|
44
|
+
|
|
45
|
+
$('body').on('click', '.add-item-button', function(){
|
|
46
|
+
var childIndex = $(this).data('childIndex');
|
|
47
|
+
var inputName = 'page[properties_attributes][' + childIndex + '][values][]';
|
|
48
|
+
var newItem =
|
|
49
|
+
"<div class='form-group'>" +
|
|
50
|
+
"<div class='col-sm-offset-2 col-sm-8'>" +
|
|
51
|
+
"<input type='text' name='" + inputName + "' class='form-control'>" +
|
|
52
|
+
"</div>" +
|
|
53
|
+
"<div class='col-sm-2'>" +
|
|
54
|
+
"<a class='btn btn-link btn-default btn-sm up-item-button'>上移</a>" +
|
|
55
|
+
"<a class='btn btn-link btn-default btn-sm remove-item-button'>删除</a>" +
|
|
56
|
+
"</div>" +
|
|
57
|
+
"</div>";
|
|
58
|
+
$(this).parents('.add-item').before(newItem);
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
$('body').on('click', '.remove-item-button', function(){
|
|
62
|
+
$(this).parents('.array-item').remove();
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
$('body').on('click', '.up-item-button', function(){
|
|
66
|
+
var $item = $(this).parents('.array-item');
|
|
67
|
+
$item.prev('.array-item').before($item);
|
|
68
|
+
})
|
|
69
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
$(function(){
|
|
2
|
+
if($('#pages-index').length <= 0){
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
var $tree = $('#manage_menu').treeview({
|
|
7
|
+
data: gon.pages,
|
|
8
|
+
onNodeSelected: function(event, data) {
|
|
9
|
+
$.get(data["href"]);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var nodes = $tree.treeview('getSelected');
|
|
14
|
+
// 默认 data 里的选中不会触发 selected event, 所以取消选中,再选中一次
|
|
15
|
+
$tree.treeview('unselectNode', [nodes]);
|
|
16
|
+
$tree.treeview('selectNode', [nodes]);
|
|
17
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//= require jquery
|
|
2
|
+
//= require jquery_ujs
|
|
3
|
+
//= require bootstrap
|
|
4
|
+
//= require bootstrap-datepicker
|
|
5
|
+
//= require bootstrap-datepicker.zh-CN
|
|
6
|
+
//= require bootstrap-treeview
|
|
7
|
+
//= require dragula
|
|
8
|
+
//= require multiselect
|
|
9
|
+
//= require kindeditor
|
|
10
|
+
//= require select2
|
|
11
|
+
//= require select2/i18n/zh-CN
|
|
12
|
+
//= require cocoon
|
|
13
|
+
|
|
14
|
+
//= require_tree ./dashboard
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// see: https://github.com/eternicode/bootstrap-datepicker/blob/master/js/locales/bootstrap-datepicker.zh-CN.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simplified Chinese translation for bootstrap-datepicker
|
|
5
|
+
* Yuan Cheung <advanimal@gmail.com>
|
|
6
|
+
*/
|
|
7
|
+
;(function($){
|
|
8
|
+
$.fn.datepicker.dates['zh-CN'] = {
|
|
9
|
+
days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
|
|
10
|
+
daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
|
|
11
|
+
daysMin: ["日", "一", "二", "三", "四", "五", "六"],
|
|
12
|
+
months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
|
|
13
|
+
monthsShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
|
|
14
|
+
today: "今日",
|
|
15
|
+
clear: "清除",
|
|
16
|
+
format: "yyyy年mm月dd日",
|
|
17
|
+
titleFormat: "yyyy年mm月",
|
|
18
|
+
weekStart: 1
|
|
19
|
+
};
|
|
20
|
+
}(jQuery));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// bootstrap
|
|
2
|
+
$grid-gutter-width: 30px !default;
|
|
3
|
+
$container-large-desktop: (940px + $grid-gutter-width) !default;
|
|
4
|
+
|
|
5
|
+
@import "bootstrap-sprockets";
|
|
6
|
+
@import "bootstrap";
|
|
7
|
+
@import "font-awesome";
|
|
8
|
+
@import "util.css/util";
|
|
9
|
+
|
|
10
|
+
@import "bootstrap-datepicker";
|
|
11
|
+
@import "dragula/dragula";
|
|
12
|
+
@import "multiselect";
|
|
13
|
+
@import "select2";
|
|
14
|
+
|
|
15
|
+
#navbar {
|
|
16
|
+
border-radius: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
label.required:before {
|
|
20
|
+
content:"* ";
|
|
21
|
+
color: red;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#modal-list li:hover {
|
|
25
|
+
cursor: move;
|
|
26
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Blacksand
|
|
2
|
+
class Dashboard::BaseController < ActionController::Base
|
|
3
|
+
layout 'blacksand/dashboard'
|
|
4
|
+
|
|
5
|
+
before_action :_authenticate!
|
|
6
|
+
before_action :_authorize!
|
|
7
|
+
|
|
8
|
+
helper_method :_current_user
|
|
9
|
+
helper_method :visible?
|
|
10
|
+
|
|
11
|
+
attr_reader :authorization_adapter
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
def _authenticate!
|
|
15
|
+
instance_eval(&Blacksand.authenticate_with)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def _authorize!
|
|
19
|
+
instance_eval(&Blacksand.authorize_with)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def _current_user
|
|
23
|
+
instance_eval(&Blacksand.current_user_method)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def visible?(action, object)
|
|
27
|
+
# 如果启用了授权
|
|
28
|
+
if self.authorization_adapter
|
|
29
|
+
return self.authorization_adapter.authorized?(action, object)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module Blacksand
|
|
2
|
+
class Dashboard::NavigationsController < Dashboard::BaseController
|
|
3
|
+
before_action :set_navigation, only: [:show, :edit, :update, :destroy]
|
|
4
|
+
|
|
5
|
+
# GET /navigations
|
|
6
|
+
# GET /navigations.json
|
|
7
|
+
def index
|
|
8
|
+
@navigations = Navigation.order(:position)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def reorder
|
|
12
|
+
navigations = params[:navigations]
|
|
13
|
+
navigations.each_with_index do |id, index|
|
|
14
|
+
Navigation.update(id, {position: index})
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
respond_to do |format|
|
|
18
|
+
format.json { render json: {success: true} }
|
|
19
|
+
format.js { flash.now.notice = '保存成功' }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# GET /navigations/1
|
|
24
|
+
# GET /navigations/1.json
|
|
25
|
+
def show
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# GET /navigations/new
|
|
29
|
+
def new
|
|
30
|
+
@navigation = Navigation.new
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# GET /navigations/1/edit
|
|
34
|
+
def edit
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# POST /navigations
|
|
38
|
+
# POST /navigations.json
|
|
39
|
+
def create
|
|
40
|
+
@navigation = Navigation.new(navigation_params)
|
|
41
|
+
|
|
42
|
+
respond_to do |format|
|
|
43
|
+
if @navigation.save
|
|
44
|
+
format.html { redirect_to navigations_url, notice: 'Navigation was successfully created.' }
|
|
45
|
+
format.json { render :show, status: :created, location: [:dashboard, @navigation] }
|
|
46
|
+
else
|
|
47
|
+
format.html { render :new }
|
|
48
|
+
format.json { render json: @navigation.errors, status: :unprocessable_entity }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# PATCH/PUT /navigations/1
|
|
54
|
+
# PATCH/PUT /navigations/1.json
|
|
55
|
+
def update
|
|
56
|
+
respond_to do |format|
|
|
57
|
+
if @navigation.update(navigation_params)
|
|
58
|
+
format.html { redirect_to navigations_url, notice: 'Navigation was successfully updated.' }
|
|
59
|
+
format.json { render :show, status: :ok, location: @navigation }
|
|
60
|
+
else
|
|
61
|
+
format.html { render :edit }
|
|
62
|
+
format.json { render json: @navigation.errors, status: :unprocessable_entity }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# DELETE /navigations/1
|
|
68
|
+
# DELETE /navigations/1.json
|
|
69
|
+
def destroy
|
|
70
|
+
@navigation.destroy
|
|
71
|
+
respond_to do |format|
|
|
72
|
+
format.html { redirect_to navigations_url, notice: 'Navigation was successfully destroyed.' }
|
|
73
|
+
format.json { head :no_content }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
79
|
+
def set_navigation
|
|
80
|
+
@navigation = Navigation.find(params[:id])
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
|
84
|
+
def navigation_params
|
|
85
|
+
params.require(:navigation).permit(:name, :url, :page_id, :position, :position, options: [ :hover_submenus, :link_sub_page ])
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
module Blacksand
|
|
2
|
+
class Dashboard::PagesController < Dashboard::BaseController
|
|
3
|
+
before_action :set_page, only: [:show, :edit, :update, :destroy, :onchange_edit, :get_prototype_id]
|
|
4
|
+
before_action :set_select, only: [:new, :edit, :onchange_new, :onchange_edit, :create, :update]
|
|
5
|
+
|
|
6
|
+
def default
|
|
7
|
+
redirect_to pages_url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def index
|
|
11
|
+
@page = Page.where(id: params[:parent_id]).first
|
|
12
|
+
@parent_id = params[:parent_id] || 0
|
|
13
|
+
@all_children = Page.where(parent_id: nil).order(:position)
|
|
14
|
+
@pages = @all_children.page(params[:page])
|
|
15
|
+
|
|
16
|
+
# 编辑只能看到自己负责的板块
|
|
17
|
+
tree_nodes = if false && current_user.role == 'editor'
|
|
18
|
+
Page.tree_nodes(current_user.page_ids)
|
|
19
|
+
else
|
|
20
|
+
Page.tree_nodes
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
gon.pages = [{
|
|
24
|
+
text: '网站',
|
|
25
|
+
href: children_partial_pages_path(parent_id: nil),
|
|
26
|
+
page_id: 0,
|
|
27
|
+
nodes: tree_nodes,
|
|
28
|
+
}]
|
|
29
|
+
|
|
30
|
+
# 选中父页面
|
|
31
|
+
Page.selectNode(gon.pages, @parent_id.to_i)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def search
|
|
35
|
+
# TODO: 查询排除自己
|
|
36
|
+
@q = Page.ransack(params[:q])
|
|
37
|
+
@pages = @q.result.page(params[:page])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def children_partial
|
|
41
|
+
@page = Page.where(id: params[:parent_id]).first
|
|
42
|
+
@parent_id = params[:parent_id]
|
|
43
|
+
@parent_page = Page.find(params[:parent_id]) if params[:parent_id]
|
|
44
|
+
@q = Page.includes(:template, :prototype).where(parent_id: params[:parent_id]).order(:position, created_at: :desc).ransack(params[:q])
|
|
45
|
+
@all_children = @q.result
|
|
46
|
+
@pages = @all_children.page(params[:page])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def show
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def new
|
|
53
|
+
@page = Page.new
|
|
54
|
+
if params["parent_id"].present?
|
|
55
|
+
@parent_id = params[:parent_id]
|
|
56
|
+
parent_page = Page.find @parent_id
|
|
57
|
+
@page.parent_id = params["parent_id"]
|
|
58
|
+
|
|
59
|
+
# Set default template
|
|
60
|
+
if parent_page.preferred_child_template_name
|
|
61
|
+
@page.template = Template.find_by(name: parent_page.preferred_child_template_name)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Set default prototype
|
|
65
|
+
if parent_page.preferred_child_prototype_name
|
|
66
|
+
prototype = Prototype.find_by(name: parent_page.preferred_child_prototype_name)
|
|
67
|
+
@page.prototype = prototype
|
|
68
|
+
prototype.fields.each do |field|
|
|
69
|
+
Property.build_property(@page, field)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def edit
|
|
76
|
+
if !@page.properties.present? && @page.prototype.present?
|
|
77
|
+
@page.build_properties
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def onchange_new
|
|
82
|
+
@page = Page.new
|
|
83
|
+
|
|
84
|
+
if params["parent_id"].present?
|
|
85
|
+
@page.parent_id = params["parent_id"]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
if params[:prototype_id].present?
|
|
89
|
+
@page.prototype_id = params[:prototype_id]
|
|
90
|
+
Prototype.find(params[:prototype_id]).fields.each do |field|
|
|
91
|
+
Property.build_property(@page, field)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
render 'onchange_render'
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def onchange_edit
|
|
98
|
+
@page.properties.destroy_all
|
|
99
|
+
if params[:prototype_id].present?
|
|
100
|
+
@page.prototype_id = params[:prototype_id]
|
|
101
|
+
@page.update_attributes(prototype_id: params[:prototype_id])
|
|
102
|
+
@page.build_properties
|
|
103
|
+
@page.save(validate: false)
|
|
104
|
+
else
|
|
105
|
+
@page.prototype_id = nil
|
|
106
|
+
@page.update_attributes(prototype_id: nil)
|
|
107
|
+
end
|
|
108
|
+
render 'onchange_render'
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def get_prototype_id
|
|
112
|
+
respond_to do |format|
|
|
113
|
+
format.json { render json: @page.prototype_id }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def create
|
|
118
|
+
@page = Page.new(page_params)
|
|
119
|
+
|
|
120
|
+
respond_to do |format|
|
|
121
|
+
if @page.save
|
|
122
|
+
format.html { redirect_to pages_url(parent_id: @page.parent_id), notice: '页面创建成功.' }
|
|
123
|
+
format.json { render :show, status: :created, location: @page }
|
|
124
|
+
else
|
|
125
|
+
puts @page.errors.full_messages
|
|
126
|
+
format.html { render :new }
|
|
127
|
+
format.json { render json: @page.errors, status: :unprocessable_entity }
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def update
|
|
133
|
+
respond_to do |format|
|
|
134
|
+
if @page.update(page_params)
|
|
135
|
+
format.html { redirect_to pages_url(parent_id: @page.parent_id), notice: '页面更新成功.' }
|
|
136
|
+
format.json { render :show, status: :ok, location: @page }
|
|
137
|
+
else
|
|
138
|
+
format.html { render :edit }
|
|
139
|
+
format.json { render json: @page.errors, status: :unprocessable_entity }
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def destroy
|
|
145
|
+
@page.destroy
|
|
146
|
+
respond_to do |format|
|
|
147
|
+
format.html { redirect_to pages_url(parent_id: @page.parent_id), notice: '成功删除.' }
|
|
148
|
+
format.json { head :no_content }
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def sort
|
|
153
|
+
params[:page].each_with_index do |id, index|
|
|
154
|
+
Page.update(id, {position: index+1})
|
|
155
|
+
end
|
|
156
|
+
render nothing: true
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
private
|
|
160
|
+
def set_page
|
|
161
|
+
@page = Page.find(params[:id])
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def set_select
|
|
165
|
+
@template_select = Template.all.map { |x| [x.name, x.id] }.sort_by {|x| x[0]}
|
|
166
|
+
@prototype_select = Prototype.all.map { |x| [x.name, x.id] }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def page_params
|
|
170
|
+
params.require(:page).permit(:title, :en_name, :parent_id, :template_id, :prototype_id, :content,
|
|
171
|
+
:properties_attributes => [:id, :type, :field_id, :value, { values: [] }, :image, :file,
|
|
172
|
+
{:pictures_attributes => [:id, :name, :file, :_destroy]}])
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
end
|
|
176
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Blacksand
|
|
2
|
+
class Dashboard::UsersController < Dashboard::BaseController
|
|
3
|
+
# layout 'manage'
|
|
4
|
+
# load_and_authorize_resource
|
|
5
|
+
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
|
6
|
+
|
|
7
|
+
# GET /users
|
|
8
|
+
# GET /users.json
|
|
9
|
+
def index
|
|
10
|
+
@users = User.normal
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# GET /users/1
|
|
14
|
+
# GET /users/1.json
|
|
15
|
+
def show
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# GET /users/new
|
|
19
|
+
def new
|
|
20
|
+
@user = User.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# GET /users/1/edit
|
|
24
|
+
def edit
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# POST /users
|
|
28
|
+
# POST /users.json
|
|
29
|
+
def create
|
|
30
|
+
@user = User.new(user_params)
|
|
31
|
+
|
|
32
|
+
respond_to do |format|
|
|
33
|
+
if @user.save
|
|
34
|
+
format.html { redirect_to dashboard_users_url, notice: t('user.user_save_success_notice') }
|
|
35
|
+
format.json { render :show, status: :created, location: @user }
|
|
36
|
+
else
|
|
37
|
+
format.html { render :new }
|
|
38
|
+
format.json { render json: @user.errors, status: :unprocessable_entity }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# PATCH/PUT /users/1
|
|
44
|
+
# PATCH/PUT /users/1.json
|
|
45
|
+
def update
|
|
46
|
+
respond_to do |format|
|
|
47
|
+
if @user.update(user_params)
|
|
48
|
+
format.html { redirect_to dashboard_users_url, notice: t('user.user_edit_success_notice') }
|
|
49
|
+
format.json { render :show, status: :ok, location: @user }
|
|
50
|
+
else
|
|
51
|
+
format.html { render :edit }
|
|
52
|
+
format.json { render json: @user.errors, status: :unprocessable_entity }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# DELETE /users/1
|
|
58
|
+
# DELETE /users/1.json
|
|
59
|
+
def destroy
|
|
60
|
+
@user.destroy
|
|
61
|
+
respond_to do |format|
|
|
62
|
+
format.html { redirect_to dashboard_users_url, notice: t('user.user_delete_success_notice') }
|
|
63
|
+
format.json { head :no_content }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
69
|
+
def set_user
|
|
70
|
+
@user = User.find(params[:id])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
|
74
|
+
def user_params
|
|
75
|
+
params.require(:user).permit(:email, :password, :password_confirmation, :role, page_ids: [])
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 与 blacksand 隔离开, 否则路由会映射到 dashboard 下面的 pages_controller
|
|
2
|
+
module BlacksandFront
|
|
3
|
+
class PagesController < ApplicationController
|
|
4
|
+
theme Blacksand.site_id
|
|
5
|
+
loan_navigations
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
@page = Blacksand::Page.find params[:id]
|
|
9
|
+
set_meta_tags title: @page.title
|
|
10
|
+
|
|
11
|
+
# render template
|
|
12
|
+
if @page.template.present?
|
|
13
|
+
render @page.template.path
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|