コミットメタ情報

リビジョン02a369d8f7e342fdcd02b5532fc579ec27c464d8 (tree)
日時2018-05-19 21:01:04
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

ログの表示範囲の選択肢を増やす

変更サマリ

差分

--- a/LogViewer/index.html
+++ b/LogViewer/index.html
@@ -106,10 +106,11 @@ var mixin = {
106106 <script>
107107 var obs = riot.observable();
108108 var spec = new Object();
109+var range = new Object();
109110 riot.mixin(mixin);
110111 riot.mount("dummy");
111-riot.mount("log-term", {observable: obs});
112-riot.mount("log-tables", {observable: obs});
112+riot.mount("log-term", {observable: obs, logRange: range});
113+riot.mount("log-tables", {observable: obs, logRange: range});
113114 riot.mount("chart-type", {observable: obs, chartSpec: spec});
114115 riot.mount("chart-range", {observable: obs, chartSpec: spec});
115116 riot.mount("sequential-chart", {observable: obs, chartSpec: spec});
--- a/LogViewer/tags.tag
+++ b/LogViewer/tags.tag
@@ -21,35 +21,58 @@ this.changeTab = function(e) {
2121 </main-tab>
2222
2323 <log-term>
24-<form id="term" show={enabled}>
25-<p>
26-<label><input type="radio" name="term" value="0" checked="checked">直近一か月</label>
27-<label><input type="radio" name="term" value="1">期間指定: </label>
24+<div id="term" show={enabled}>
25+<ul class="tab tabsub" style="float: left; margin-right: 0.2em">
26+ <li each={name, i in rangeTabs} class={select: opts.logRange.val === i} onclick={parent.rangeTabChange}>{name}</li>
27+</ul>
28+<div style="padding: 0.2em 0;">
2829 <input type="text" id="term_from" style="width: 7em">~<input type="text" id="term_to" style="width: 7em">
29-<input type="button" id="term_apply" value="適用">
30-</p>
31-</form>
30+</div>
31+</div>
3232
3333 <script>
34-this.on("mount", function() {
35- $('#term_from').datepicker({
36- defaultDate: moment().subtract(1, 'months').toDate(),
37- onClose: function() { $('input[name=term]').val(['1']); }
38- });
39- $('#term_to').datepicker({
40- onClose: function() { $('input[name=term]').val(['1']); }
41- });
42- $('#term_apply').click(function() {
43- opts.observable.trigger("termApplied");
44- });
45-});
34+var self = this;
35+
36+this.rangeTabs = [
37+"今日",
38+"今週",
39+"今月",
40+"すべて",
41+"期間指定"
42+];
4643
4744 this.enabled = false;
48-var self = this;
4945
5046 opts.observable.on("mainTabChanged", function(idx) {
5147 self.update({enabled: idx >= 0 && idx < self.logTables});
5248 });
49+
50+var val = sessionStorage.getItem('logRange');
51+opts.logRange.val = val === null ? 2 : +val;
52+
53+this.init = function() {
54+ $('#term_from').datepicker({
55+ onClose: function() {
56+ if (opts.logRange.val === 4)
57+ opts.observable.trigger("logRangeChanged");
58+ }
59+ });
60+ $('#term_to').datepicker({
61+ onClose: function() {
62+ if (opts.logRange.val === 4)
63+ opts.observable.trigger("logRangeChanged");
64+ }
65+ });
66+};
67+
68+this.on("mount", this.init);
69+
70+this.rangeTabChange = function(e) {
71+ sessionStorage.setItem("logRange", e.item.i);
72+ opts.logRange.val = e.item.i;
73+ opts.observable.trigger("logRangeChanged");
74+};
75+
5376 </script>
5477 </log-term>
5578
@@ -98,7 +121,7 @@ opts.observable.on("mainTabChanged", function(idx) {
98121 self.show();
99122 });
100123
101-opts.observable.on("termApplied", function() {
124+opts.observable.on("logRangeChanged", function() {
102125 self.show();
103126 });
104127
@@ -133,14 +156,53 @@ this.init = function() {
133156 this.show = function() {
134157 if (this.mainTab >= this.jsons.length)
135158 return;
136- var query = "?from=" + moment().subtract(1, 'months').valueOf();
137- if ($('input[name=term]:eq(1)').prop('checked')) {
138- var from = $('#term_from').datepicker("getDate");
159+ var now = moment();
160+ var from;
161+ var query = "?from=";
162+ switch (opts.logRange.val){
163+ case 0:
164+ from = now.clone().startOf('day').hours(5);
165+ if (now.hour() < 5)
166+ from.subtract(1, 'days');
167+ query += from.valueOf();
168+ break;
169+ case 1:
170+ from = now.clone().startOf('week').hours(5);
171+ if (now.hour() < 5 && now.days() === 1)
172+ from.subtract(1, 'weeks');
173+ query += from.valueOf();
174+ break;
175+ case 2:
176+ if (now.hours() >= 22 &&
177+ now.dates() === now.clone().endOf('month').date()) {
178+ from = now.clone().hours(22);
179+ } else {
180+ from = now.clone().startOf('month').subtract(1, 'days').hours(22);
181+ }
182+ query += from.valueOf();
183+ break;
184+ case 3:
185+ query = "";
186+ break;
187+ case 4:
188+ from = $('#term_from').datepicker("getDate");
139189 var to = $('#term_to').datepicker("getDate");
140- if (from !== null)
141- query = "?from=" + from.valueOf();
142- if (to !== null)
143- query += "&to=" + (to.valueOf() + this.oneDay);
190+ if (from === null)
191+ return;
192+ from = moment(from);
193+ if (from.date() === 1)
194+ from.subtract(2, 'hours');
195+ query += from.valueOf();
196+ if (to !== null) {
197+ to = moment(to);
198+ if (to.date() === to.clone().endOf('month').date()) {
199+ to.hour(22);
200+ } else {
201+ to.add(1, 'days').hours(5);
202+ }
203+ query += "&to=" + to.valueOf();
204+ }
205+ break;
144206 }
145207 $('#loading').show();
146208 var url = this.jsons[this.mainTab] + query;
@@ -250,11 +312,11 @@ this.init = function() {
250312 });
251313 };
252314
253-this.on("mount", this.init);
254-
255315 this.mainTab = 0;
256316 var self = this;
257317
318+this.on("mount", self.init);
319+
258320 opts.observable.on("mainTabChanged", function(idx) {
259321 self.update({mainTab: idx});
260322 });
@@ -300,7 +362,7 @@ this.resize = function() {
300362 };
301363
302364 this.drawChart = function(data) {
303- range = this.calcRange(opts.chartSpec.seqRange);
365+ var range = this.calcRange(opts.chartSpec.seqRange);
304366 if (range.last === 0)
305367 return;
306368 if (!data) {
@@ -347,7 +409,7 @@ this.calcRange = function(range) {
347409 break;
348410 }
349411 return {first: first, last: last};
350-}
412+};
351413
352414 this.unselected = {};
353415
@@ -506,7 +568,7 @@ this.resize = function() {
506568 };
507569
508570 this.drawChart = function(data) {
509- range = this.calcRange(opts.chartSpec.diffRange);
571+ var range = this.calcRange(opts.chartSpec.diffRange);
510572 if (range.last === 0)
511573 return;
512574 if (!data) {
@@ -552,7 +614,7 @@ this.calcRange = function(range) {
552614 break;
553615 }
554616 return {first: first, last: last};
555-}
617+};
556618
557619 this.unselected = {};
558620
旧リポジトリブラウザで表示