From b17cd50693373660b4ebbb9b397f565b67e96900 Mon Sep 17 00:00:00 2001 From: Tuomas Nurmi Date: Fri, 18 Nov 2022 22:19:04 +0200 Subject: [PATCH 1/2] Allow setting default location for weather widget In cases where all of the users are from the same geographical area, it would be extremely useful to be able to set a default location for the dashboard weather widget. With these changes, this option becomes available, as default values can be set with occ config:app:set weather_status [lat,lon,altitude,address] --value 'value' These changes also implement the path 2 described in feature request https://github.com/nextcloud/server/issues/27908 denied in 2021 Signed-off-by: Tuomas Nurmi --- .../lib/Service/WeatherStatusService.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php index ed416d09a87f2..18a02134a5032 100644 --- a/apps/weather_status/lib/Service/WeatherStatusService.php +++ b/apps/weather_status/lib/Service/WeatherStatusService.php @@ -287,9 +287,9 @@ private function searchForAddress(string $address): array { * @return WeatherStatusLocationWithMode which contains coordinates, formatted address and current weather status mode */ public function getLocation(): array { - $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', ''); - $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', ''); - $address = $this->config->getUserValue($this->userId, Application::APP_ID, 'address', ''); + $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', $this->config->getAppValue(Application::APP_ID, 'lat', '')); + $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', $this->config->getAppValue(Application::APP_ID, 'lat', '')); + $address = $this->config->getUserValue($this->userId, Application::APP_ID, 'address', $this->config->getAppValue(Application::APP_ID, 'address', '')); $mode = $this->config->getUserValue($this->userId, Application::APP_ID, 'mode', self::MODE_MANUAL_LOCATION); return [ 'lat' => $lat, @@ -305,9 +305,9 @@ public function getLocation(): array { * @return WeatherStatusForecast[]|array{error: string}|WeatherStatusSuccess which contains success state and filtered forecast data */ public function getForecast(): array { - $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', ''); - $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', ''); - $alt = $this->config->getUserValue($this->userId, Application::APP_ID, 'altitude', ''); + $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', $this->config->getAppValue(Application::APP_ID, 'lat', '')); + $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', $this->config->getAppValue(Application::APP_ID, 'lon', '')); + $alt = $this->config->getUserValue($this->userId, Application::APP_ID, 'altitude', $this->config->getAppValue(Application::APP_ID, 'altitude', '')); if (!is_numeric($alt)) { $alt = 0; } From 357f073d486c3c88a5f7f492192901e2924c5e7d Mon Sep 17 00:00:00 2001 From: Tuomas Nurmi Date: Mon, 21 Nov 2022 11:16:10 +0200 Subject: [PATCH 2/2] Fix typo in weather default location setting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was 'lat' instead of 'lon', thanks for catching! Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Tuomas Nurmi --- apps/weather_status/lib/Service/WeatherStatusService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php index 18a02134a5032..b8c623f8c7f88 100644 --- a/apps/weather_status/lib/Service/WeatherStatusService.php +++ b/apps/weather_status/lib/Service/WeatherStatusService.php @@ -288,7 +288,7 @@ private function searchForAddress(string $address): array { */ public function getLocation(): array { $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', $this->config->getAppValue(Application::APP_ID, 'lat', '')); - $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', $this->config->getAppValue(Application::APP_ID, 'lat', '')); + $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', $this->config->getAppValue(Application::APP_ID, 'lon', '')); $address = $this->config->getUserValue($this->userId, Application::APP_ID, 'address', $this->config->getAppValue(Application::APP_ID, 'address', '')); $mode = $this->config->getUserValue($this->userId, Application::APP_ID, 'mode', self::MODE_MANUAL_LOCATION); return [