upmin-admin 0.0.37 → 0.0.38

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05591a19f31e85ef3e32d1032bf0886455336995
4
- data.tar.gz: 5be32b7cc779891aefc057edbe0f37f0f70aaa5d
3
+ metadata.gz: 6bd7cc2583a8e2019373b7628b6fee2ff186c526
4
+ data.tar.gz: f7f129e4e4f4e2691c9822d9cff24cffdccddd56
5
5
  SHA512:
6
- metadata.gz: 3f88b68c678d08d330ea6ffe1dcb1465c47a314c211014b512eec9b7d0d5d3bb421d4a070329fbcec02f59023229680df3bdc0cf0c4e81cd02f8cc149d650dc6
7
- data.tar.gz: e5320ae6d314197694b4d23c9ef693efea999b87889239a51cab542787f49f0d68087aaadb97d23bb62dada48fa41fb1e06d4c16330c32e3f5839752aedceabc
6
+ metadata.gz: 03e51d88c3c4552e02605da44b6cae42a70c0f86f8bcbeab1950c199d063ca6c5cf2757550525ee16ee3624bc1914f1bd52f6cec69ff7cb0e458f1def3c0cd76
7
+ data.tar.gz: 40284c1fe7e51a3acd9d1b13397548db8d695648dbc0aa74fa97089f8f27992b372eec98adb87e06116173f5985c0541d09c2569a833df60843dc4e93fb7a9f7
@@ -15,6 +15,7 @@
15
15
  //= require ./jquery-clockpicker
16
16
  //= require ./moment
17
17
  //= require ./pikaday
18
+ //= require ./helpers
18
19
  //= require_tree .
19
20
 
20
21
  function runUpmin() {
@@ -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
+ })();
@@ -1,3 +1,11 @@
1
+ .upmin-model input.boolean {
2
+ float: left;
3
+ height: auto;
4
+ margin: 4px 8px;
5
+ clear:both;
6
+ }
7
+
8
+
1
9
  ol.progbar {
2
10
  margin: 0 0 50px 0;
3
11
  padding: 0;
@@ -8,8 +8,6 @@ body {
8
8
  .navbar {
9
9
 
10
10
  background-color: #2c3e50;
11
- height: 60px;
12
-
13
11
  }
14
12
 
15
13
  .btn {
@@ -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).page(@page).per(30)
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] || 0
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.
@@ -4,7 +4,7 @@
4
4
  -# TODO(jon): Add pagination w/ search results
5
5
  = up_search_results(@q, @results)
6
6
  %br
7
- = paginate @results
7
+ = up_paginate @results
8
8
  %br
9
9
  %br
10
10
  .col-md-4
@@ -0,0 +1,8 @@
1
+ - boolean ||= "false"
2
+
3
+ - if editable && f = form_builder
4
+ = f.check_box(attr_name, value: boolean, class: "boolean")
5
+
6
+ - else
7
+ %p.well
8
+ = f.check_box(attr_name, {value: boolean, class: "boolean", disabled: "disabled"})
@@ -1,92 +1,33 @@
1
1
  - datetime ||= nil
2
+ - datetime_str = datetime.utc.iso8601 if datetime
2
3
  - if editable && f = form_builder
3
- = f.hidden_field(attr_name, value: datetime)
4
- - # TODO(jon): Figure out a better way to do transforms. This works for now though.
5
- = f.hidden_field("transforms[#{attr_name}]", value: "DateTime#parse")
6
- .row
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: datetime, id: "#{form_id}-date"}
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 => datetime, id: "#{form_id}-time"}
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
- var datePicker,
24
- hiddenInput = $('##{form_id}'),
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
@@ -0,0 +1,7 @@
1
+ - float ||= nil
2
+ - if editable && f = form_builder
3
+ = f.text_field(attr_name, value: float, class: "form-control")
4
+
5
+ - else
6
+ %p.well
7
+ = float
@@ -0,0 +1,7 @@
1
+ - text ||= nil
2
+ - if editable && f = form_builder
3
+ = f.text_area(attr_name, value: text, rows: 4, class: "form-control")
4
+
5
+ - else
6
+ %p.well
7
+ = text
@@ -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
- require "kaminari"
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Upmin
2
- VERSION = "0.0.37"
2
+ VERSION = "0.0.38"
3
3
  end
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.37
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-11 00:00:00.000000000 Z
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