upmin-admin 0.0.37 → 0.0.38
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 +4 -4
- data/app/assets/javascripts/upmin/application.js +1 -0
- data/app/assets/javascripts/upmin/attributes/datetime.js +134 -0
- data/app/assets/javascripts/upmin/helpers.js +0 -0
- data/app/assets/stylesheets/upmin/attributes.css.scss +8 -0
- data/app/assets/stylesheets/upmin/base.css.scss +0 -2
- data/app/controllers/upmin/models_controller.rb +3 -3
- data/app/views/upmin/models/search.html.haml +1 -1
- data/app/views/upmin/partials/attributes/_boolean.html.haml +8 -0
- data/app/views/upmin/partials/attributes/_datetime.html.haml +15 -74
- data/app/views/upmin/partials/attributes/_float.html.haml +7 -0
- data/app/views/upmin/partials/attributes/_text.html.haml +7 -0
- data/lib/upmin/admin.rb +7 -1
- data/lib/upmin/paginator.rb +14 -0
- data/lib/upmin/railtie.rb +2 -0
- data/lib/upmin/railties/paginator.rb +14 -0
- data/lib/upmin/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd7cc2583a8e2019373b7628b6fee2ff186c526
|
4
|
+
data.tar.gz: f7f129e4e4f4e2691c9822d9cff24cffdccddd56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03e51d88c3c4552e02605da44b6cae42a70c0f86f8bcbeab1950c199d063ca6c5cf2757550525ee16ee3624bc1914f1bd52f6cec69ff7cb0e458f1def3c0cd76
|
7
|
+
data.tar.gz: 40284c1fe7e51a3acd9d1b13397548db8d695648dbc0aa74fa97089f8f27992b372eec98adb87e06116173f5985c0541d09c2569a833df60843dc4e93fb7a9f7
|
@@ -0,0 +1,134 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
// Methods used in datetime parsing and setting.
|
4
|
+
function parseDate(dateString) {
|
5
|
+
var matches = dateString.match(/(\d+).(\d+).(\d+)/i);
|
6
|
+
if (matches == null || matches.length < 4) {
|
7
|
+
return null;
|
8
|
+
} else {
|
9
|
+
var m = moment();
|
10
|
+
m.utc().year(matches[1]);
|
11
|
+
m.utc().month(matches[2]);
|
12
|
+
m.utc().date(matches[3]);
|
13
|
+
return m;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
function setInputDate(newMoment, hiddenInput) {
|
18
|
+
if (newMoment == null || !newMoment.isValid()) {
|
19
|
+
hiddenInput.val("");
|
20
|
+
return null;
|
21
|
+
}
|
22
|
+
|
23
|
+
var curMoment = moment(hiddenInput.val());
|
24
|
+
if (!curMoment.isValid()) {
|
25
|
+
curMoment = newMoment;
|
26
|
+
} else {
|
27
|
+
curMoment.utc().year(newMoment.utc().year());
|
28
|
+
curMoment.utc().month(newMoment.utc().month());
|
29
|
+
curMoment.utc().date(newMoment.utc().date());
|
30
|
+
}
|
31
|
+
hiddenInput.val(curMoment.utc().format());
|
32
|
+
return curMoment;
|
33
|
+
}
|
34
|
+
|
35
|
+
function parseTime(timeString) {
|
36
|
+
var matches = timeString.match(/(\d+)(?::(\d\d))?\s*(p?)/i);
|
37
|
+
if (matches == null || matches.length < 4) {
|
38
|
+
return null;
|
39
|
+
} else {
|
40
|
+
var m = moment();
|
41
|
+
|
42
|
+
var h = parseInt(matches[1]);
|
43
|
+
if (h == 12 && !matches[3]) {
|
44
|
+
h = 0
|
45
|
+
} else if (matches[3]) {
|
46
|
+
h += (h < 12) ? 12 : 0;
|
47
|
+
}
|
48
|
+
m.utc().hour(h);
|
49
|
+
m.utc().minute(matches[2]);
|
50
|
+
return m;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
function setInputTime(newMoment, hiddenInput) {
|
55
|
+
if (newMoment == null || !newMoment.isValid()) {
|
56
|
+
hiddenInput.val("");
|
57
|
+
return null;
|
58
|
+
}
|
59
|
+
|
60
|
+
var curMoment = moment(hiddenInput.val());
|
61
|
+
if (!curMoment.isValid()) {
|
62
|
+
curMoment = newMoment;
|
63
|
+
} else {
|
64
|
+
curMoment.utc().hour(newMoment.utc().hour());
|
65
|
+
curMoment.utc().minute(newMoment.utc().minute());
|
66
|
+
}
|
67
|
+
hiddenInput.val(curMoment.utc().format());
|
68
|
+
return curMoment;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
// Initializing the attribute view.
|
77
|
+
var init = function(formId) {
|
78
|
+
var dtSection = $("." + formId + ".datetime-attribute");
|
79
|
+
var hiddenInput = dtSection.find("input#" + formId + "[type=hidden]");
|
80
|
+
var dateInput = dtSection.find("#" + formId + "-date");
|
81
|
+
var timeInput = dtSection.find("#" + formId + "-time");
|
82
|
+
|
83
|
+
var dtMoment = moment(hiddenInput.val());
|
84
|
+
if (hiddenInput.val() == "") {
|
85
|
+
dtMoment = null;
|
86
|
+
}
|
87
|
+
|
88
|
+
var handleDateSelect = function() {
|
89
|
+
var newDateMoment = parseDate(dateInput.val());
|
90
|
+
setInputDate(newDateMoment, hiddenInput);
|
91
|
+
return newDateMoment;
|
92
|
+
}
|
93
|
+
|
94
|
+
var handleTimeSelect = function() {
|
95
|
+
var newTimeMoment = parseTime(timeInput.val());
|
96
|
+
setInputTime(newTimeMoment, hiddenInput);
|
97
|
+
return newTimeMoment;
|
98
|
+
}
|
99
|
+
|
100
|
+
// Create Date Picker
|
101
|
+
var datePicker = new Pikaday({ field: $("#" + formId + "-date")[0], onSelect: handleDateSelect });
|
102
|
+
|
103
|
+
// Create Time Picker
|
104
|
+
$("#" + formId + "-time").clockpicker({
|
105
|
+
autoclose: true,
|
106
|
+
donetext: "Done",
|
107
|
+
twelvehour: true,
|
108
|
+
afterDone: handleTimeSelect,
|
109
|
+
});
|
110
|
+
|
111
|
+
if (dtMoment != null) {
|
112
|
+
timeInput.val(dtMoment.utc().format("hh:mmA"));
|
113
|
+
}
|
114
|
+
|
115
|
+
dtSection.closest("form").submit(function(event) {
|
116
|
+
event.preventDefault();
|
117
|
+
|
118
|
+
// Only date is *required* so the order here is important.
|
119
|
+
handleTimeSelect();
|
120
|
+
handleDateSelect();
|
121
|
+
|
122
|
+
event.target.submit();
|
123
|
+
});
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
if (window.Upmin == null) {
|
128
|
+
window.Upmin = {};
|
129
|
+
}
|
130
|
+
if (window.Upmin.Attributes == null) {
|
131
|
+
window.Upmin.Attributes = {};
|
132
|
+
}
|
133
|
+
window.Upmin.Attributes.DateTime = init;
|
134
|
+
})();
|
File without changes
|
@@ -27,7 +27,7 @@ module Upmin
|
|
27
27
|
# TODO(jon): Figure out a better way to do transforms.
|
28
28
|
# This could cause issues and is exploitable, but it
|
29
29
|
# should be fine for now since this is only on admin pages
|
30
|
-
if transforms[key]
|
30
|
+
if transforms[key] and not value.blank?
|
31
31
|
value = transform(transforms, key, value)
|
32
32
|
end
|
33
33
|
|
@@ -45,7 +45,7 @@ module Upmin
|
|
45
45
|
|
46
46
|
def search
|
47
47
|
@q = @klass.ransack(params[:q])
|
48
|
-
@results = @q.result(distinct: true)
|
48
|
+
@results = Upmin::Paginator.paginate(@q.result(distinct: true), @page, 30)
|
49
49
|
end
|
50
50
|
|
51
51
|
def action
|
@@ -80,7 +80,7 @@ module Upmin
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def set_page
|
83
|
-
@page = params[:page] ||
|
83
|
+
@page = params[:page] || 1
|
84
84
|
end
|
85
85
|
|
86
86
|
# TODO(jon): Figure out a better way to do transforms that is easy to extend.
|
@@ -1,92 +1,33 @@
|
|
1
1
|
- datetime ||= nil
|
2
|
+
- datetime_str = datetime.utc.iso8601 if datetime
|
2
3
|
- if editable && f = form_builder
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
.row.datetime-attribute{class: form_id}
|
5
|
+
= f.hidden_field(attr_name, value: datetime_str)
|
6
|
+
- # TODO(jon): Figure out a better way to do transforms. This works for now though.
|
7
|
+
= f.hidden_field("transforms[#{attr_name}]", value: "DateTime#parse")
|
8
|
+
|
7
9
|
.col-xs-12.col-md-4
|
8
10
|
.input-group.pikadate
|
9
|
-
%input.form-control{type: :text, value:
|
11
|
+
%input.form-control{type: :text, value: datetime_str, id: "#{form_id}-date"}
|
10
12
|
%span.input-group-addon
|
11
13
|
%span.glyphicon.glyphicon-calendar
|
14
|
+
|
12
15
|
.col-xs-12.col-md-4
|
13
16
|
.input-group.clockpicker{"data-align" => "top", "data-autoclose" => "true", "data-placement" => "right"}
|
14
|
-
%input.form-control{:type => "text", :value =>
|
17
|
+
%input.form-control{:type => "text", :value => datetime_str, id: "#{form_id}-time"}
|
15
18
|
%span.input-group-addon
|
16
19
|
%span.glyphicon.glyphicon-time
|
17
20
|
|
21
|
+
.col-xs-12.col-md-4
|
22
|
+
%small
|
23
|
+
Date & Time are shown in UTC. If not time is provided, the current time in UTC will be used.
|
18
24
|
|
19
25
|
|
20
26
|
- content_for(:javascript) do
|
21
27
|
:javascript
|
22
|
-
(function() {
|
23
|
-
|
24
|
-
|
25
|
-
date = new Date(hiddenInput.val());
|
26
|
-
|
27
|
-
// Date Specific Code
|
28
|
-
var handleDateSelect = function() {
|
29
|
-
var pickerDate = datePicker.getDate();
|
30
|
-
console.log("Setting the date from " + date + " to " + pickerDate);
|
31
|
-
|
32
|
-
date.setUTCFullYear(pickerDate.getUTCFullYear());
|
33
|
-
date.setUTCMonth(pickerDate.getUTCMonth());
|
34
|
-
date.setUTCDate(pickerDate.getUTCDate());
|
35
|
-
|
36
|
-
hiddenInput.val(date.toUTCString());
|
37
|
-
}
|
38
|
-
|
39
|
-
datePicker = new Pikaday({ field: $('##{form_id}-date')[0], onSelect: handleDateSelect });
|
40
|
-
|
41
|
-
// Time Specific Code
|
42
|
-
var timeInput = $('##{form_id}-time');
|
43
|
-
|
44
|
-
var parseTime = function(timeString) {
|
45
|
-
var ret = new Date();
|
46
|
-
|
47
|
-
var time = timeString.match(/(\d+)(?::(\d\d))?\s*(p?)/i);
|
48
|
-
if (!time) {
|
49
|
-
return NaN;
|
50
|
-
}
|
51
|
-
var hours = parseInt(time[1], 10);
|
52
|
-
if (hours == 12 && !time[3]) {
|
53
|
-
hours = 0;
|
54
|
-
} else {
|
55
|
-
hours += (hours < 12 && time[3]) ? 12 : 0;
|
56
|
-
}
|
57
|
-
|
58
|
-
ret.setHours(hours);
|
59
|
-
ret.setMinutes(parseInt(time[2], 10) || 0);
|
60
|
-
ret.setSeconds(0, 0);
|
61
|
-
return ret;
|
62
|
-
}
|
63
|
-
|
64
|
-
var handleTimeSelect = function() {
|
65
|
-
var time = parseTime(timeInput.val());
|
66
|
-
|
67
|
-
date.setUTCHours(time.getUTCHours());
|
68
|
-
date.setUTCMinutes(time.getUTCMinutes());
|
69
|
-
|
70
|
-
hiddenInput.val(date.toUTCString());
|
71
|
-
}
|
72
|
-
|
73
|
-
timeInput.clockpicker({
|
74
|
-
autoclose: true,
|
75
|
-
donetext: "Done",
|
76
|
-
twelvehour: true,
|
77
|
-
afterDone: handleTimeSelect,
|
78
|
-
default: date.getHours() + ":" + date.getMinutes()
|
79
|
-
});
|
80
|
-
|
81
|
-
timeInput.val(date.getHours() + ":" + date.getMinutes());
|
82
|
-
|
83
|
-
|
84
|
-
// Make sure we set times when the form is input in case the user typed in values.
|
85
|
-
timeInput.closest("form").submit(function(event) {
|
86
|
-
// TODO(jon): Add code to handle typed in dates.
|
87
|
-
handleTimeSelect();
|
88
|
-
});
|
89
|
-
})();
|
28
|
+
$(document).ready(function() {
|
29
|
+
window.Upmin.Attributes.DateTime("#{form_id}");
|
30
|
+
});
|
90
31
|
|
91
32
|
|
92
33
|
- else
|
data/lib/upmin/admin.rb
CHANGED
@@ -4,17 +4,23 @@ require "upmin/engine"
|
|
4
4
|
require "upmin/klass"
|
5
5
|
require "upmin/model"
|
6
6
|
|
7
|
+
require "upmin/paginator"
|
8
|
+
|
7
9
|
# Monkey patch code into rails
|
8
10
|
require "upmin/railties/active_record"
|
11
|
+
require "upmin/railties/paginator"
|
9
12
|
require "upmin/railties/render"
|
10
13
|
require "upmin/railties/render_helpers"
|
11
14
|
require "upmin/railtie"
|
12
15
|
|
13
16
|
# gems and stuff we use
|
17
|
+
require "jquery-rails"
|
14
18
|
require "ransack"
|
15
19
|
require "haml"
|
16
20
|
require "sass-rails"
|
17
|
-
|
21
|
+
|
22
|
+
# If WillPaginate is present we just use it, but by default upmin-admin uses Kaminari
|
23
|
+
require "kaminari" unless defined?(WillPaginate)
|
18
24
|
|
19
25
|
module Upmin
|
20
26
|
module Admin
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Upmin
|
2
|
+
module Paginator
|
3
|
+
|
4
|
+
def Paginator.paginate(chain, page = 1, per_page = 30)
|
5
|
+
if defined?(WillPaginate)
|
6
|
+
# Ignore per page for now - just use the will_paginate default
|
7
|
+
return chain.page(page.to_i)
|
8
|
+
else # Use Kaminari
|
9
|
+
return chain.page(page).per(per_page)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
data/lib/upmin/railtie.rb
CHANGED
@@ -9,10 +9,12 @@ module Upmin
|
|
9
9
|
|
10
10
|
ActiveSupport.on_load(:action_controller) do
|
11
11
|
::ActionController::Base.send(:include, Upmin::Railties::Render)
|
12
|
+
::ActionController::Base.send(:include, Upmin::Railties::Paginator)
|
12
13
|
end
|
13
14
|
|
14
15
|
ActiveSupport.on_load(:action_view) do
|
15
16
|
::ActionView::Base.send(:include, Upmin::Railties::Render)
|
17
|
+
::ActionView::Base.send(:include, Upmin::Railties::Paginator)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module Upmin::Railties
|
3
|
+
module Paginator
|
4
|
+
|
5
|
+
def up_paginate(scope, options = {}, &block)
|
6
|
+
if defined?(WillPaginate)
|
7
|
+
return will_paginate(scope, options)
|
8
|
+
else # Use Kaminari
|
9
|
+
return paginate(scope, options, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
data/lib/upmin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upmin-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Calhoun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -106,6 +106,8 @@ files:
|
|
106
106
|
- app/assets/images/upmin/logo_large.png
|
107
107
|
- app/assets/images/upmin/logo_small.png
|
108
108
|
- app/assets/javascripts/upmin/application.js
|
109
|
+
- app/assets/javascripts/upmin/attributes/datetime.js
|
110
|
+
- app/assets/javascripts/upmin/helpers.js
|
109
111
|
- app/assets/javascripts/upmin/jquery-clockpicker.js
|
110
112
|
- app/assets/javascripts/upmin/models.js
|
111
113
|
- app/assets/javascripts/upmin/moment.js
|
@@ -131,10 +133,13 @@ files:
|
|
131
133
|
- app/views/upmin/models/show.html.haml
|
132
134
|
- app/views/upmin/partials/actions/_action.html.haml
|
133
135
|
- app/views/upmin/partials/associations/_associations.html.haml
|
136
|
+
- app/views/upmin/partials/attributes/_boolean.html.haml
|
134
137
|
- app/views/upmin/partials/attributes/_datetime.html.haml
|
138
|
+
- app/views/upmin/partials/attributes/_float.html.haml
|
135
139
|
- app/views/upmin/partials/attributes/_integer.html.haml
|
136
140
|
- app/views/upmin/partials/attributes/_progress_bar.html.haml
|
137
141
|
- app/views/upmin/partials/attributes/_string.html.haml
|
142
|
+
- app/views/upmin/partials/attributes/_text.html.haml
|
138
143
|
- app/views/upmin/partials/attributes/_unknown.html.haml
|
139
144
|
- app/views/upmin/partials/models/_model.html.haml
|
140
145
|
- app/views/upmin/partials/search_boxes/_ransack_search_box.html.haml
|
@@ -148,8 +153,10 @@ files:
|
|
148
153
|
- lib/upmin/engine.rb
|
149
154
|
- lib/upmin/klass.rb
|
150
155
|
- lib/upmin/model.rb
|
156
|
+
- lib/upmin/paginator.rb
|
151
157
|
- lib/upmin/railtie.rb
|
152
158
|
- lib/upmin/railties/active_record.rb
|
159
|
+
- lib/upmin/railties/paginator.rb
|
153
160
|
- lib/upmin/railties/render.rb
|
154
161
|
- lib/upmin/railties/render_helpers.rb
|
155
162
|
- lib/upmin/version.rb
|