You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2016/12/22 08:40:57 UTC
incubator-eagle git commit: [EAGLE-847] support timezone
Repository: incubator-eagle
Updated Branches:
refs/heads/master 73642a4ee -> 4f4a7a3b3
[EAGLE-847] support timezone
Sync UI timezone with eagle server: '/rest/server/config' -> '/service/timezone'
timezone sample: 'UTC+8'
Author: zombieJ <sm...@gmail.com>
Closes #754 from zombieJ/EAGLE-847.
Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/4f4a7a3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/4f4a7a3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/4f4a7a3b
Branch: refs/heads/master
Commit: 4f4a7a3b349f005c4eae5642ba7ed8006235cf61
Parents: 73642a4
Author: zombieJ <sm...@gmail.com>
Authored: Thu Dec 22 16:40:22 2016 +0800
Committer: Hao Chen <ha...@apache.org>
Committed: Thu Dec 22 16:40:22 2016 +0800
----------------------------------------------------------------------
eagle-server/src/main/webapp/app/dev/index.html | 1 +
.../app/dev/partials/integration/siteList.html | 2 +-
.../src/main/webapp/app/dev/public/js/app.js | 7 +-
.../app/dev/public/js/services/serverSrv.js | 40 +++++++++
.../app/dev/public/js/services/timeSrv.js | 85 ++++++++++++--------
5 files changed, 98 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4f4a7a3b/eagle-server/src/main/webapp/app/dev/index.html
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/index.html b/eagle-server/src/main/webapp/app/dev/index.html
index 47e1b76..ec0a76a 100644
--- a/eagle-server/src/main/webapp/app/dev/index.html
+++ b/eagle-server/src/main/webapp/app/dev/index.html
@@ -265,6 +265,7 @@
<!-- Service -->
<script src="public/js/services/main.js" type="text/javascript" charset="utf-8"></script>
+ <script src="public/js/services/serverSrv.js" type="text/javascript" charset="utf-8"></script>
<script src="public/js/services/timeSrv.js" type="text/javascript" charset="utf-8"></script>
<script src="public/js/services/pageSrv.js" type="text/javascript" charset="utf-8"></script>
<script src="public/js/services/widgetSrv.js" type="text/javascript" charset="utf-8"></script>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4f4a7a3b/eagle-server/src/main/webapp/app/dev/partials/integration/siteList.html
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/partials/integration/siteList.html b/eagle-server/src/main/webapp/app/dev/partials/integration/siteList.html
index ab29a79..6d2627c 100644
--- a/eagle-server/src/main/webapp/app/dev/partials/integration/siteList.html
+++ b/eagle-server/src/main/webapp/app/dev/partials/integration/siteList.html
@@ -23,7 +23,7 @@
<th>Site</th>
<th>Description</th>
<th>Enabled Apps</th>
- <th width="95">Actions</th>
+ <th width="100">Actions</th>
</tr>
</thead>
<tbody>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4f4a7a3b/eagle-server/src/main/webapp/app/dev/public/js/app.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/app.js b/eagle-server/src/main/webapp/app/dev/public/js/app.js
index 87cae11..e1f5b77 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/app.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/app.js
@@ -57,6 +57,10 @@ var app = {};
// TODO: need auth module
}
+ resolve.Server = function (Server) {
+ return Server.getPromise();
+ };
+
resolve.Site = function (Site) {
return Site.getPromise(config);
};
@@ -256,8 +260,9 @@ var app = {};
// ======================================================================================
// = Main Controller =
// ======================================================================================
- eagleApp.controller('MainCtrl', function ($scope, $wrapState, $urlRouter, PageConfig, Portal, Widget, Entity, CompatibleEntity, Site, Application, UI, Time, Policy) {
+ eagleApp.controller('MainCtrl', function ($scope, $wrapState, $urlRouter, Server, PageConfig, Portal, Widget, Entity, CompatibleEntity, Site, Application, UI, Time, Policy) {
window._WrapState = $scope.$wrapState = $wrapState;
+ window._Server = $scope.Server = Server;
window._PageConfig = $scope.PageConfig = PageConfig;
window._Portal = $scope.Portal = Portal;
window._Widget = $scope.Widget = Widget;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4f4a7a3b/eagle-server/src/main/webapp/app/dev/public/js/services/serverSrv.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/services/serverSrv.js b/eagle-server/src/main/webapp/app/dev/public/js/services/serverSrv.js
new file mode 100644
index 0000000..334cb79
--- /dev/null
+++ b/eagle-server/src/main/webapp/app/dev/public/js/services/serverSrv.js
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function() {
+ 'use strict';
+
+ var serviceModule = angular.module('eagle.service');
+
+ serviceModule.service('Server', function($q, $wrapState, Entity) {
+ var Server = {
+ config: {},
+ };
+
+ var serverPromise = Entity.query('server/config')._then(function (res) {
+ Server.config = res.data;
+ return Server;
+ });
+
+ Server.getPromise = function () {
+ return serverPromise;
+ };
+
+ return Server;
+ });
+}());
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/4f4a7a3b/eagle-server/src/main/webapp/app/dev/public/js/services/timeSrv.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/services/timeSrv.js b/eagle-server/src/main/webapp/app/dev/public/js/services/timeSrv.js
index 2c8e168..552d452 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/services/timeSrv.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/services/timeSrv.js
@@ -30,7 +30,7 @@
var keepTime = false;
var serviceModule = angular.module('eagle.service');
- serviceModule.service('Time', function($q, $wrapState) {
+ serviceModule.service('Time', function($q, $wrapState, Server) {
var startTime, endTime;
var reloadListenerList = [];
@@ -100,12 +100,26 @@
$Time.autoRefresh = false;
$Time._reloadListenerList = reloadListenerList;
- // TODO: time zone
$Time.UTC_OFFSET = 0;
$Time.FORMAT = "YYYY-MM-DD HH:mm:ss";
$Time.SHORT_FORMAT = "MM-DD HH:mm";
+ // UTC sync
+ Server.getPromise().then(function () {
+ var timezone = Server.config.service.timezone || "";
+ try {
+ var match = timezone.match(/^(UTC|GMT)([+-]\d+)?$/);
+ if (match) {
+ $Time.UTC_OFFSET = Number(match[2] || 0) * 60;
+ } else {
+ console.warn('Timezone parse failed:', timezone);
+ }
+ } catch (err) {
+ console.error('Timezone not support:', timezone, err);
+ }
+ });
+
$Time.format = function (time, format) {
time = $Time(time);
return time ? time.format(format || $Time.FORMAT) : "-";
@@ -237,44 +251,45 @@
$Time.getPromise = function (config, state, param) {
var deferred = $q.defer();
-
var timeConfig = typeof config.time === true ? {} : config.time;
- // Ignore time update if customise time set.
- if(keepTime) {
- // Update auto refresh mark if time is generated from promise
- if(autoGenerateTime && timeConfig) {
- $Time.autoRefresh = timeConfig.autoRefresh;
- }
-
- autoGenerateTime = false;
- keepTime = false;
- deferred.resolve($Time);
- } else {
- if (timeConfig) {
- $Time.pickerType = timeConfig.type || $Time.TIME_RANGE_PICKER;
-
- startTime = $Time.verifyTime(param.startTime);
- endTime = $Time.verifyTime(param.endTime);
-
- if (!startTime || !endTime) {
- endTime = $Time();
- startTime = endTime.clone().subtract(2, "hour");
-
- autoGenerateTime = true;
- keepTime = true;
- $Time._innerSearch = {
- startTime: $Time.format(startTime),
- endTime: $Time.format(endTime)
- };
+ Server.getPromise().then(function () {
+ // Ignore time update if customise time set.
+ if(keepTime) {
+ // Update auto refresh mark if time is generated from promise
+ if(autoGenerateTime && timeConfig) {
+ $Time.autoRefresh = timeConfig.autoRefresh;
}
+
+ autoGenerateTime = false;
+ keepTime = false;
+ deferred.resolve($Time);
} else {
- $Time._innerSearch = null;
- $Time.pickerType = null;
- $Time.autoRefresh = false;
+ if (timeConfig) {
+ $Time.pickerType = timeConfig.type || $Time.TIME_RANGE_PICKER;
+
+ startTime = $Time.verifyTime(param.startTime);
+ endTime = $Time.verifyTime(param.endTime);
+
+ if (!startTime || !endTime) {
+ endTime = $Time();
+ startTime = endTime.clone().subtract(2, "hour");
+
+ autoGenerateTime = true;
+ keepTime = true;
+ $Time._innerSearch = {
+ startTime: $Time.format(startTime),
+ endTime: $Time.format(endTime)
+ };
+ }
+ } else {
+ $Time._innerSearch = null;
+ $Time.pickerType = null;
+ $Time.autoRefresh = false;
+ }
+ deferred.resolve($Time);
}
- deferred.resolve($Time);
- }
+ });
return deferred.promise;
};