diff options
author | Gunnar Mills <gmills@us.ibm.com> | 2018-07-18 13:01:48 -0500 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2018-09-13 00:38:58 +0000 |
commit | b7ea279015fd33574eeab24b114b19d0cdb22e3c (patch) | |
tree | d3d60c80e6d66e5074f805959575611116c0b871 /app/configuration/controllers/date-time-controller.js | |
parent | 264c5b8a131fbb554fa4804cc77095a741a0c7e7 (diff) | |
download | phosphor-webui-b7ea279015fd33574eeab24b114b19d0cdb22e3c.tar.gz phosphor-webui-b7ea279015fd33574eeab24b114b19d0cdb22e3c.zip |
Set time fields
Squashed 5 commits to set the date-time fields:
time mode, time owner, BMC time, and host time.
Also included is a commit to display the timezone.
Set time mode
Moved the selection of NTP vs Manual (time mode) to a radio
button.
Added code to allow the user set it.
Tested: Set the time mode on a Witherspoon.
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Set time owner
The time owner is now a dropdown and is set when "Save settings"
is pressed.
Tested: Set the time owner on a Witherspoon
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Set the BMC and Host time
The BMC and host have the same time except when time mode is split.
Only need to set BMC or host time when time mode is not split.
When time mode is split, set both. Use time owner to determine
which to set.
https://github.com/openbmc/phosphor-time-manager#time-settings
Have date and time as two separate inputs, this is due to Firefox
not supporting "datetime-local". The "date" and "time" input
fields are more widely supported.
https://caniuse.com/#feat=input-datetime
The idea for 2 separate input fields came from:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
Must set the time mode and time owner before setting the time,
this is due to permissions of who can set the time.
Tested: Set the date and time on a Witherspoon.
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Add NTP Servers
The user can now view and set NTP Servers.
Moved setFocusOnNewInput to a common directive since it is used
on the NTP Servers and the DNS Servers on the network page.
Even though NTPServers is a network interface specific path
(e.g. /xyz/openbmc_project/network/eth0/attr/NTPServers) it acts
like a global setting, openbmc/phosphor-time-manager#4.
Using eth0 for setting and getting the NTP Servers until
NTPServers is moved to a non-network interface specific path.
In Redfish, NTPServers is a non-network interface specific.
Tested: Set NTP Servers on a Witherspoon.
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Add timezone
Added the timezone for the host and bmc date time.
The timezone looks like "GMT-0400 (EDT)" or "GMT-0500 (CDT)".
I got this from
https://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript
and choose this formatting over something like "America/Chicago".
Tested: See the timezone on a Witherspoon
Change-Id: I59a4449d63f73a6ed14cb934f3d8577e46620c4e
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'app/configuration/controllers/date-time-controller.js')
-rw-r--r-- | app/configuration/controllers/date-time-controller.js | 161 |
1 files changed, 145 insertions, 16 deletions
diff --git a/app/configuration/controllers/date-time-controller.js b/app/configuration/controllers/date-time-controller.js index cbc7443..02752fe 100644 --- a/app/configuration/controllers/date-time-controller.js +++ b/app/configuration/controllers/date-time-controller.js @@ -10,35 +10,164 @@ window.angular && (function(angular) { 'use strict'; angular.module('app.configuration').controller('dateTimeController', [ - '$scope', '$window', 'APIUtils', - function($scope, $window, APIUtils) { - $scope.bmc_time = ''; + '$scope', '$window', 'APIUtils', '$route', '$q', + function($scope, $window, APIUtils, $route, $q) { + $scope.bmc = {}; + $scope.host = {}; + $scope.ntp = {servers: []}; $scope.time_mode = ''; $scope.time_owner = ''; + $scope.time_owners = ['BMC', 'Host', 'Both', 'Split']; + $scope.set_time_error = false; + $scope.set_time_success = false; $scope.loading = true; + var time_path = '/xyz/openbmc_project/time/'; var getTimePromise = APIUtils.getTime().then( function(data) { - $scope.bmc_time = - data.data['/xyz/openbmc_project/time/bmc'].Elapsed / 1000; - $scope.host_time = - data.data['/xyz/openbmc_project/time/host'].Elapsed / 1000; - - $scope.time_owner = data.data['/xyz/openbmc_project/time/owner'] - .TimeOwner.split('.') - .pop(); - $scope.time_mode = - data.data['/xyz/openbmc_project/time/sync_method'] - .TimeSyncMethod.split('.') - .pop(); + // The time is returned as Epoch microseconds convert to + // milliseconds. + if (data.data[time_path + 'bmc'] && + data.data[time_path + 'bmc'].hasOwnProperty('Elapsed')) { + $scope.bmc.date = + new Date(data.data[time_path + 'bmc'].Elapsed / 1000); + // Don't care about milliseconds and don't want them displayed + $scope.bmc.date.setMilliseconds(0); + // https://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript + // GMT-0400 (EDT) + $scope.bmc.timezone = + $scope.bmc.date.toString().match(/([A-Z]+[\+-][0-9]+.*)/)[1]; + } + if (data.data[time_path + 'host'] && + data.data[time_path + 'host'].hasOwnProperty('Elapsed')) { + $scope.host.date = + new Date(data.data[time_path + 'host'].Elapsed / 1000); + $scope.host.date.setMilliseconds(0); + $scope.host.timezone = + $scope.host.date.toString().match(/([A-Z]+[\+-][0-9]+.*)/)[1]; + } + if (data.data[time_path + 'owner'] && + data.data[time_path + 'owner'].hasOwnProperty('TimeOwner')) { + $scope.time_owner = + data.data[time_path + 'owner'].TimeOwner.split('.').pop(); + } + if (data.data[time_path + 'sync_method'] && + data.data[time_path + 'sync_method'].hasOwnProperty( + 'TimeSyncMethod')) { + $scope.time_mode = data.data[time_path + 'sync_method'] + .TimeSyncMethod.split('.') + .pop(); + } }, function(error) { console.log(JSON.stringify(error)); }); - getTimePromise.finally(function() { + var getNTPPromise = APIUtils.getNTPServers().then( + function(data) { + $scope.ntp.servers = data.data; + }, + function(error) { + console.log(JSON.stringify(error)); + }); + + var promises = [ + getTimePromise, + getNTPPromise, + ]; + + $q.all(promises).finally(function() { $scope.loading = false; }); + + $scope.setTime = function() { + $scope.set_time_error = false; + $scope.set_time_success = false; + $scope.loading = true; + var promises = [setTimeMode(), setTimeOwner(), setNTPServers()]; + + $q.all(promises).then( + function() { + // Have to set the time mode and time owner first to avoid a + // insufficient permissions if the time mode or time owner had + // changed. + var manual_promises = []; + if ($scope.time_mode == 'Manual') { + // If owner is 'Split' set both. + // If owner is 'Host' set only it. + // Else set BMC only. See: + // https://github.com/openbmc/phosphor-time-manager/blob/master/README.md + if ($scope.time_owner != 'Host') { + manual_promises.push(setBMCTime()); + } + + if ($scope.time_owner == 'Host' || + $scope.time_owner == 'Split') { + manual_promises.push(setHostTime()); + } + } + $q.all(manual_promises) + .then( + function() { + $scope.set_time_success = true; + }, + function(errors) { + console.log(JSON.stringify(errors)); + $scope.set_time_error = true; + }) + .finally(function() { + $scope.loading = false; + }); + }, + function(errors) { + console.log(JSON.stringify(errors)); + $scope.set_time_error = true; + $scope.loading = false; + }); + }; + $scope.refresh = function() { + $route.reload(); + }; + + $scope.addNTPField = function() { + $scope.ntp.servers.push(''); + }; + + function setNTPServers() { + // Remove any empty strings from the array. Important because we add an + // empty string to the end so the user can add a new NTP server, if the + // user doesn't fill out the field, we don't want to add. + $scope.ntp.servers = $scope.ntp.servers.filter(Boolean); + // NTP servers does not allow an empty array, since we remove all empty + // strings above, could have an empty array. TODO: openbmc/openbmc#3240 + if ($scope.ntp.servers.length == 0) { + $scope.ntp.servers.push(''); + } + return APIUtils.setNTPServers($scope.ntp.servers); + } + + function setTimeMode() { + return APIUtils.setTimeMode( + 'xyz.openbmc_project.Time.Synchronization.Method.' + + $scope.time_mode); + } + + function setTimeOwner() { + return APIUtils.setTimeOwner( + 'xyz.openbmc_project.Time.Owner.Owners.' + $scope.time_owner); + } + + function setBMCTime() { + // Add the separate date and time objects and convert to Epoch time in + // microseconds. + return APIUtils.setBMCTime($scope.bmc.date.getTime() * 1000); + } + + function setHostTime() { + // Add the separate date and time objects and convert to Epoch time + // microseconds. + return APIUtils.setHostTime($scope.host.date.getTime() * 1000); + } } ]); })(angular); |