navigation_light 0.1.0
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/README.md +83 -0
- data/Rakefile +32 -0
- data/app/assets/config/navigation_light_manifest.js +2 -0
- data/app/assets/javascripts/navigation_light/application.js +15 -0
- data/app/assets/stylesheets/navigation_light/application.css +15 -0
- data/app/controllers/navigation_light/application_controller.rb +5 -0
- data/app/helpers/navigation_light/application_helper.rb +4 -0
- data/app/jobs/navigation_light/application_job.rb +4 -0
- data/app/mailers/navigation_light/application_mailer.rb +6 -0
- data/app/models/navigation_light/application_record.rb +69 -0
- data/app/models/navigation_light/count.rb +39 -0
- data/app/models/navigation_light/label.rb +27 -0
- data/app/models/navigation_light/middle_label.rb +10 -0
- data/app/models/navigation_light/on_load.rb +16 -0
- data/app/models/navigation_light/relation_label.rb +13 -0
- data/app/models/navigation_light/relation_uuid.rb +54 -0
- data/app/models/navigation_light/time.rb +78 -0
- data/app/models/navigation_light/uuid.rb +47 -0
- data/app/views/layouts/navigation_light/application.html.erb +16 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20200210090159_create_navigation_light_uuids.rb +19 -0
- data/db/migrate/20200211025417_create_navigation_light_labels.rb +41 -0
- data/db/migrate/20200213161530_create_navigation_light_times.rb +37 -0
- data/db/migrate/seed.rb +28 -0
- data/lib/navigation_light.rb +5 -0
- data/lib/navigation_light/engine.rb +14 -0
- data/lib/navigation_light/version.rb +3 -0
- data/lib/tasks/navigation_light_tasks.rake +4 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78a67fb74ad6324faa2c522a203ef79ff7395ae2ee008a2b53f254ebf3aa8025
|
4
|
+
data.tar.gz: 82c40f7884122c8b13469176a4b04556642526ea17b85a49584cccc7ac11f994
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6e96de9bdb751f41d8e6b6ab739664690977e521c5f497643c58b8d4931c9418f72778109ff899899eef451b31326cbd9ba8564f68b641dc30c2dbe30f0cb85
|
7
|
+
data.tar.gz: a8bd91cb6a4528875385f844fa70bbbb67d640aec2c6f07cba259bd2cfcc3c34ba4439a5dd8ac899ffcddc3a963d74b6244fd2b3962edf910460021ba02c0668
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 ff4c00
|
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/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
<!-- TOC -->
|
2
|
+
|
3
|
+
- [说明](#说明)
|
4
|
+
- [用途](#用途)
|
5
|
+
- [返回值](#返回值)
|
6
|
+
- [示例](#示例)
|
7
|
+
- [源码地址](#源码地址)
|
8
|
+
- [接驳](#接驳)
|
9
|
+
- [使用](#使用)
|
10
|
+
- [Uuid](#uuid)
|
11
|
+
- [Lable](#lable)
|
12
|
+
- [Count](#count)
|
13
|
+
- [Time](#time)
|
14
|
+
- [License](#license)
|
15
|
+
- [多多指教](#多多指教)
|
16
|
+
|
17
|
+
<!-- /TOC -->
|
18
|
+
|
19
|
+
# 说明
|
20
|
+
|
21
|
+
## 用途
|
22
|
+
|
23
|
+
> 航行灯用作指示飞机的方位.<br>本项目应用于为应用系统中数据记录提供定位服务.
|
24
|
+
|
25
|
+
定位服务包括:
|
26
|
+
|
27
|
+
0. 精确定位, 即通过索引值从整个数据库中查询出涉及的具体数据记录.
|
28
|
+
0. 标签定位, 通过为数据添加标签使得可根据标签定位范围内数据.
|
29
|
+
0. 频率定位, 通过对数据进行时间及标签关联,进行个性化统计.
|
30
|
+
0. 时间定位, 对目标数据进行 分/时/天/月/季度/年 时间索引,属于标签定位的细分领域.
|
31
|
+
|
32
|
+
## 返回值
|
33
|
+
|
34
|
+
全局采用统一标准返回值格式(BJ-FHB-2020-0111):
|
35
|
+
|
36
|
+
[布尔值<sup>[1]</sup>, '文字说明'<sup>[2]</sup>, {error_message: '异常描述', error_path: '异常发生信息', other:{}}<sup>[3]</sup>]
|
37
|
+
|
38
|
+
<hr>
|
39
|
+
|
40
|
+
1: 用于标记程序执行结果是否符合程序预期
|
41
|
+
|
42
|
+
2: 可供直接显示的结果提示信息(不包含系统敏感信息)
|
43
|
+
|
44
|
+
3: 非必需, 用于程序发生异常时,提供异常详细信息
|
45
|
+
|
46
|
+
### 示例
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
[true, '操作成功']
|
50
|
+
|
51
|
+
[false, '操作失败', {error_message: '异常描述', error_path: '异常发生信息', other:{}}]
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
## 源码地址
|
56
|
+
|
57
|
+
[GitLab | NavigationLight]((https://gitlab.com/ff4c00/hijack/-/blob/master/BackEnd/Ruby/Article/C919/NavigationLight.md))
|
58
|
+
|
59
|
+
# 接驳
|
60
|
+
|
61
|
+
# 使用
|
62
|
+
|
63
|
+
## Uuid
|
64
|
+
|
65
|
+
> 为数据生成全局唯一的uuid.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
relation_navigation_light :uuid
|
69
|
+
```
|
70
|
+
|
71
|
+
## Lable
|
72
|
+
|
73
|
+
## Count
|
74
|
+
|
75
|
+
## Time
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
80
|
+
|
81
|
+
# 多多指教
|
82
|
+
|
83
|
+
* <a href="mailto:ff4c00@gmail.com">个人联系邮箱</a>
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
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 = 'NavigationLight'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
@@ -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. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require activestorage
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
class ApplicationRecord < ActiveRecord::Base
|
3
|
+
self.abstract_class = true
|
4
|
+
|
5
|
+
def ejection(type: 'back_result')
|
6
|
+
case type
|
7
|
+
when 'back_result', 'normal'
|
8
|
+
# send(type.to_sym, yield)
|
9
|
+
send(type.to_sym) do
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
else
|
13
|
+
raise '参数(type), 赋值异常'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# def self.inherited(child_class)
|
18
|
+
|
19
|
+
# child_class.class_eval do |klass|
|
20
|
+
# # def klass.ejection
|
21
|
+
# # puts 'fine'
|
22
|
+
# # puts "#{self}"
|
23
|
+
# # end
|
24
|
+
# # def klass.ejection(*args, &block)
|
25
|
+
# # self.new.ejection(*args, &block)
|
26
|
+
# # end
|
27
|
+
|
28
|
+
# # def klass.ejection(type: 'back_result')
|
29
|
+
# # # self.new.ejection(type: type) do
|
30
|
+
# # # # yield
|
31
|
+
# # # p "#{super}"
|
32
|
+
# # # end
|
33
|
+
# # end
|
34
|
+
|
35
|
+
# # class << self
|
36
|
+
# # def ejection
|
37
|
+
# # p 'as'
|
38
|
+
# # end
|
39
|
+
# # end
|
40
|
+
|
41
|
+
# # define_method :ejection do
|
42
|
+
# # puts self
|
43
|
+
# # end
|
44
|
+
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
private
|
49
|
+
def back_result
|
50
|
+
begin
|
51
|
+
return (res = [false, '系统错误', '调用方法请提供相应代码块']) unless block_given?
|
52
|
+
res = yield
|
53
|
+
rescue
|
54
|
+
res = [false, '系统运行时异常', {error_message: $!, error_path: $@}]
|
55
|
+
ensure
|
56
|
+
return res
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def normal
|
61
|
+
begin
|
62
|
+
yield
|
63
|
+
rescue => e
|
64
|
+
raise e
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
module Count < ApplicationRecord
|
3
|
+
def self.included(target)
|
4
|
+
target.class_eval do
|
5
|
+
has_many :times, as: :timeable, :dependent => :destroy
|
6
|
+
|
7
|
+
count = NavigationLight::Label.find_by(code: 'NavigationLight::Count')
|
8
|
+
count && count.children.where.not(code: nil).uniq.each do |label|
|
9
|
+
|
10
|
+
define_method("add_#{label.code}".to_sym) do |*args, &block|
|
11
|
+
time = Time.new
|
12
|
+
time.labels << label
|
13
|
+
self.times << time
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method("summary_#{label.code}s".to_sym) do |*args, &block|
|
17
|
+
times = self.times.included(:labels).where("navigation_light_labels.code in ?", label.code)
|
18
|
+
|
19
|
+
Time::ABOUT_TIME_COLUMNS.each do |column|
|
20
|
+
define_method(column.to_sym) do |*args, &block|
|
21
|
+
times.where(column => args[0]).counts
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Time::ABOUT_TIME_COLUMNS.each do |column|
|
26
|
+
define_method("summary_#{label.code}s_#{column}".to_sym) do |*args, &block|
|
27
|
+
column(*args, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
times.counts
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
class Label < ApplicationRecord
|
3
|
+
|
4
|
+
relation_navigation_light :uuid
|
5
|
+
|
6
|
+
before_save :validate_columns
|
7
|
+
|
8
|
+
has_ancestry
|
9
|
+
has_ancestry :cache_depth => true
|
10
|
+
|
11
|
+
acts_as_paranoid
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def validate_columns
|
16
|
+
validate_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_name
|
20
|
+
# 判断是否为空
|
21
|
+
unless self.name.present?
|
22
|
+
self.errors[:name] << '标签名称不能为空'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
module OnLoad
|
3
|
+
|
4
|
+
def relation_navigation_light(*models)
|
5
|
+
models.each do |model|
|
6
|
+
raise "model名称错误, #{model} 不在允许加载model范围内." unless [:uuid, :label].include?(model.to_sym)
|
7
|
+
end
|
8
|
+
|
9
|
+
models.each do |model|
|
10
|
+
include "NavigationLight::Relation#{model.capitalize}".constantize
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
module RelationUuid
|
3
|
+
|
4
|
+
def self.included(target)
|
5
|
+
target.class_eval do
|
6
|
+
|
7
|
+
has_one :uuid_, as: :uuidable, :dependent => :destroy
|
8
|
+
|
9
|
+
before_save :generate_columns
|
10
|
+
before_save :validate_columns
|
11
|
+
|
12
|
+
def uuid
|
13
|
+
unless self.uuid_
|
14
|
+
generate_uuid_
|
15
|
+
end
|
16
|
+
|
17
|
+
unless self.uuid_.uuid
|
18
|
+
self.uuid_.send(:generate_uuid)
|
19
|
+
end
|
20
|
+
|
21
|
+
self.uuid_.uuid
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def generate_columns
|
27
|
+
generate_uuid_
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_columns
|
31
|
+
validate_uuid_
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_uuid_
|
35
|
+
self.uuid_ = Uuid.new unless self.uuid_
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_uuid_
|
39
|
+
# 判断是否为空
|
40
|
+
unless self.uuid_.present?
|
41
|
+
self.errors[:uuid_] << 'uuid_尚未生成'
|
42
|
+
end
|
43
|
+
|
44
|
+
unless self.uuid.present?
|
45
|
+
self.errors[:uuid] << 'uuid尚未生成'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
class Time < ApplicationRecord
|
3
|
+
|
4
|
+
belongs_to :timeable, :polymorphic => true
|
5
|
+
|
6
|
+
relation_navigation_light :uuid, :label
|
7
|
+
|
8
|
+
before_save :generate_columns
|
9
|
+
|
10
|
+
ABOUT_TIME_COLUMNS = [:minute, :hour, :day, :week, :month, :quarter, :year]
|
11
|
+
|
12
|
+
private
|
13
|
+
def generate_columns
|
14
|
+
tmp = {}
|
15
|
+
ABOUT_TIME_COLUMNS.each do |column|
|
16
|
+
next if self.send(column).present?
|
17
|
+
tmp.merge!({column => Time.send("index_#{column}")})
|
18
|
+
end
|
19
|
+
self.attributes = self.attributes.merge!(tmp.stringify_keys)
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
|
24
|
+
def index_minute(time: ::Time.now)
|
25
|
+
time.strftime('%M').to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def index_hour(time: ::Time.now)
|
29
|
+
time.strftime('%H').to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def index_day(time: ::Time.now)
|
33
|
+
time.strftime('%Y%m%d').to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def index_month(time: ::Time.now)
|
37
|
+
time.strftime('%Y%m').to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
def index_week(time: ::Time.now)
|
41
|
+
year = time.strftime('%Y').to_i
|
42
|
+
week = time.strftime('%W').to_i
|
43
|
+
num = Date.commercial( year.to_i, 52, 1 ).strftime('%W')
|
44
|
+
if num.to_i == 52
|
45
|
+
if week == 0
|
46
|
+
return ((year-1).to_s << "52").to_i
|
47
|
+
elsif week == 53
|
48
|
+
return ((year+1).to_s << "01").to_i
|
49
|
+
else
|
50
|
+
return time.strftime('%Y%W').to_i
|
51
|
+
end
|
52
|
+
else
|
53
|
+
if week + 1 == 53
|
54
|
+
return ((year+1).to_s << "01").to_i
|
55
|
+
else
|
56
|
+
return time.strftime('%Y%W').to_i + 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def index_quarter(time: ::Time.now)
|
62
|
+
quarter = case time.strftime('%m').to_i
|
63
|
+
when 1,2,3 then 1
|
64
|
+
when 4,5,6 then 2
|
65
|
+
when 7,8,9 then 3
|
66
|
+
when 10,11,12 then 4
|
67
|
+
end
|
68
|
+
return (time.strftime('%Y') << "0" << quarter.to_s).to_i
|
69
|
+
end
|
70
|
+
|
71
|
+
def index_year(time: ::Time.now)
|
72
|
+
time.strftime('%Y').to_i
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
class Uuid < ApplicationRecord
|
3
|
+
# uuid 不需要假删除 甚至不能删除
|
4
|
+
|
5
|
+
belongs_to :uuidable, :polymorphic => true
|
6
|
+
|
7
|
+
# 多个 before_save 会按照从上往下顺序执行
|
8
|
+
before_save :generate_columns
|
9
|
+
before_save :validate_columns
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def generate_columns
|
14
|
+
ejection(type: 'normal') do
|
15
|
+
generate_uuid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_columns
|
20
|
+
validate_uuid
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_uuid
|
24
|
+
# 判断是否为空
|
25
|
+
unless self.uuid.present?
|
26
|
+
self.errors[:uuid] << '唯一标识不能为空'
|
27
|
+
end
|
28
|
+
|
29
|
+
# 判断是否重复
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_uuid
|
33
|
+
flag = !(self.uuid.present?)
|
34
|
+
uuid = self.uuid
|
35
|
+
|
36
|
+
(flag = Uuid.where.not(id: self.id).exists?(uuid: uuid)) unless flag
|
37
|
+
|
38
|
+
while flag
|
39
|
+
uuid = SecureRandom.uuid
|
40
|
+
flag = Uuid.exists?(uuid: uuid)
|
41
|
+
end
|
42
|
+
|
43
|
+
self.uuid = uuid
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Navigation light</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag "navigation_light/application", media: "all" %>
|
9
|
+
<%= javascript_include_tag "navigation_light/application" %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<%= yield %>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateNavigationLightUuids < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :navigation_light_uuids do |t|
|
4
|
+
t.string :uuid, null: false, unique: true
|
5
|
+
t.index :uuid, unique: true
|
6
|
+
|
7
|
+
t.integer :uuidable_id, null: false
|
8
|
+
t.index :uuidable_id
|
9
|
+
|
10
|
+
t.string :uuidable_type, null: false
|
11
|
+
t.index :uuidable_type
|
12
|
+
|
13
|
+
t.datetime :deleted_at
|
14
|
+
t.index :deleted_at
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class CreateNavigationLightLabels < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :navigation_light_labels do |t|
|
4
|
+
t.string :name, null: false, unique: true, comment: '标签名称'
|
5
|
+
t.index :name, unique: true
|
6
|
+
|
7
|
+
t.string :synopsis, comment: '简介'
|
8
|
+
|
9
|
+
t.string :code, comment: '编码', null: false, unique: true
|
10
|
+
t.index [:code, :ancestry], unique: true
|
11
|
+
|
12
|
+
t.datetime :deleted_at
|
13
|
+
t.index :deleted_at
|
14
|
+
|
15
|
+
# 树状结构相关
|
16
|
+
t.string :ancestry
|
17
|
+
t.index [:ancestry]
|
18
|
+
t.integer :ancestry_depth, default: 404
|
19
|
+
t.index :ancestry_depth
|
20
|
+
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table :navigation_light_middle_labels do |t|
|
25
|
+
t.integer :middlabel_id, null: false
|
26
|
+
t.index :middlabel_id
|
27
|
+
|
28
|
+
t.string :middlabel_type, null: false
|
29
|
+
t.index :middlabel_type
|
30
|
+
|
31
|
+
t.integer :label_id, null: false
|
32
|
+
t.index :label_id
|
33
|
+
|
34
|
+
t.datetime :deleted_at
|
35
|
+
t.index :deleted_at
|
36
|
+
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class CreateNavigationLightTimes < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :navigation_light_times do |t|
|
4
|
+
t.integer :minute, null: false
|
5
|
+
t.index :minute
|
6
|
+
|
7
|
+
t.integer :hour, null: false
|
8
|
+
t.index :hour
|
9
|
+
|
10
|
+
t.integer :day, null: false
|
11
|
+
t.index :day
|
12
|
+
|
13
|
+
t.integer :week, null: false
|
14
|
+
t.index :week
|
15
|
+
|
16
|
+
t.integer :month, null: false
|
17
|
+
t.index :month
|
18
|
+
|
19
|
+
t.integer :quarter, null: false
|
20
|
+
t.index :quarter
|
21
|
+
|
22
|
+
t.integer :year, null: false
|
23
|
+
t.index :year
|
24
|
+
|
25
|
+
t.integer :timeable_id, null: false
|
26
|
+
t.index :timeable_id
|
27
|
+
|
28
|
+
t.string :timeable_type, null: false
|
29
|
+
t.index :timeable_type
|
30
|
+
|
31
|
+
t.datetime :deleted_at
|
32
|
+
t.index :deleted_at
|
33
|
+
|
34
|
+
t.timestamps
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/db/migrate/seed.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
def initialize_label_data
|
2
|
+
@object = NavigationLight::Label.find_or_initialize_by(code: 'Object')
|
3
|
+
@object.update(name: 'Object', synopsis: 'Object')
|
4
|
+
|
5
|
+
def initialize_model_data
|
6
|
+
@model = @object.children.find_or_initialize_by(code: 'Model')
|
7
|
+
@model.update(name: '表结构', synopsis: '数据库表结构使用标签')
|
8
|
+
|
9
|
+
def initialize_count_data
|
10
|
+
@count = @model.children.find_or_initialize_by(code: 'NavigationLight::Count')
|
11
|
+
@count.update(name: '统计', synopsis: '有关统计专用标签合集')
|
12
|
+
|
13
|
+
[
|
14
|
+
{name: '使用次数', synopsis: '数据的使用次数', code: 'used_count'},
|
15
|
+
{name: '查看次数', synopsis: '数据的查看次数', code: 'view_count'}
|
16
|
+
].each do |hash|
|
17
|
+
data = @count.children.find_or_initialize_by(code: hash[:code])
|
18
|
+
data.update(hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
initialize_count_data
|
23
|
+
end
|
24
|
+
|
25
|
+
initialize_model_data
|
26
|
+
end
|
27
|
+
|
28
|
+
initialize_label_data
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module NavigationLight
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace NavigationLight
|
4
|
+
|
5
|
+
require 'ancestry'
|
6
|
+
require 'paranoia'
|
7
|
+
require 'pry-byebug'
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveSupport.on_load :active_record do
|
13
|
+
send :extend, NavigationLight::OnLoad
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: navigation_light
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ff4c00
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ancestry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: paranoia
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.4.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.4.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.8.0
|
83
|
+
description: 本项目应用于为应用系统中数据记录提供定位服务
|
84
|
+
email:
|
85
|
+
- ff4c00@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- app/assets/config/navigation_light_manifest.js
|
94
|
+
- app/assets/javascripts/navigation_light/application.js
|
95
|
+
- app/assets/stylesheets/navigation_light/application.css
|
96
|
+
- app/controllers/navigation_light/application_controller.rb
|
97
|
+
- app/helpers/navigation_light/application_helper.rb
|
98
|
+
- app/jobs/navigation_light/application_job.rb
|
99
|
+
- app/mailers/navigation_light/application_mailer.rb
|
100
|
+
- app/models/navigation_light/application_record.rb
|
101
|
+
- app/models/navigation_light/count.rb
|
102
|
+
- app/models/navigation_light/label.rb
|
103
|
+
- app/models/navigation_light/middle_label.rb
|
104
|
+
- app/models/navigation_light/on_load.rb
|
105
|
+
- app/models/navigation_light/relation_label.rb
|
106
|
+
- app/models/navigation_light/relation_uuid.rb
|
107
|
+
- app/models/navigation_light/time.rb
|
108
|
+
- app/models/navigation_light/uuid.rb
|
109
|
+
- app/views/layouts/navigation_light/application.html.erb
|
110
|
+
- config/routes.rb
|
111
|
+
- db/migrate/20200210090159_create_navigation_light_uuids.rb
|
112
|
+
- db/migrate/20200211025417_create_navigation_light_labels.rb
|
113
|
+
- db/migrate/20200213161530_create_navigation_light_times.rb
|
114
|
+
- db/migrate/seed.rb
|
115
|
+
- lib/navigation_light.rb
|
116
|
+
- lib/navigation_light/engine.rb
|
117
|
+
- lib/navigation_light/version.rb
|
118
|
+
- lib/tasks/navigation_light_tasks.rake
|
119
|
+
homepage: https://gitlab.com/ff4c00/navigation_light
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.7.8
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: ''
|
143
|
+
test_files: []
|