Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ build/
coverage/
vendor
.php_cs.cache
.php-cs-fixer.cache
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions js/photos-main.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@
* Released under the MIT License.
*/

/*!
* escape-html
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
* MIT Licensed
*/

/*!
* vuex v3.6.2
* (c) 2021 Evan You
* @license MIT
*/

/*!
* focus-trap 6.9.4
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*/

/*!
* tabbable 5.3.3
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/

/*! For license information please see AppNavigation.js.LICENSE.txt */

/*! For license information please see AppNavigationItem.js.LICENSE.txt */

/*! For license information please see AppNavigationSettings.js.LICENSE.txt */
/*! For license information please see AppSettingsDialog.js.LICENSE.txt */

/*! For license information please see CheckboxRadioSwitch.js.LICENSE.txt */

/*! Hammer.JS - v2.0.7 - 2016-04-22
* http://hammerjs.github.io/
Expand Down
2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*!
* focus-trap 6.9.4
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*/

/*!
* tabbable 5.3.3
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/
* escape-html
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
* MIT Licensed
*/

/*! For license information please see ncvuecomponents.js.LICENSE.txt */

Expand Down

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Photos\Controller;

use OCA\Photos\AppInfo\Application;
use OCA\Photos\Service\UserConfigService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
Expand Down Expand Up @@ -66,8 +67,11 @@ public function setUserConfig(string $key, string $value): JSONResponse {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}

$userId = $user->getUid();
$this->config->setUserValue($userId, Application::APP_ID, $key, $value);
if (!in_array($key, array_keys(UserConfigService::DEFAULT_CONFIGS))) {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}

$this->config->setUserValue($user->getUid(), Application::APP_ID, $key, $value);
return new JSONResponse([], Http::STATUS_OK);
}

Expand Down
34 changes: 19 additions & 15 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OC\User\NoUserException;
use OCA\Files\Event\LoadSidebar;
use OCA\Photos\AppInfo\Application;
use OCA\Photos\Service\UserConfigService;
use OCA\Viewer\Event\LoadViewer;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
Expand All @@ -46,8 +47,7 @@
use OCP\Files\Search\ISearchComparison;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\AppFramework\Services\IInitialState;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Util;
Expand All @@ -56,8 +56,8 @@
class PageController extends Controller {
private IAppManager $appManager;
private IEventDispatcher $eventDispatcher;
private IConfig $config;
private IInitialStateService $initialStateService;
private UserConfigService $userConfig;
private IInitialState $initialState;
private IUserSession $userSession;
private IRootFolder $rootFolder;
private ICacheFactory $cacheFactory;
Expand All @@ -68,8 +68,8 @@ public function __construct(
IRequest $request,
IAppManager $appManager,
IEventDispatcher $eventDispatcher,
IConfig $config,
IInitialStateService $initialStateService,
UserConfigService $userConfig,
IInitialState $initialState,
IUserSession $userSession,
IRootFolder $rootFolder,
ICacheFactory $cacheFactory,
Expand All @@ -79,8 +79,8 @@ public function __construct(

$this->appManager = $appManager;
$this->eventDispatcher = $eventDispatcher;
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userConfig = $userConfig;
$this->initialState = $initialState;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->cacheFactory = $cacheFactory;
Expand All @@ -101,12 +101,16 @@ public function index(): TemplateResponse {
$this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar());
$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());

$this->initialStateService->provideInitialState($this->appName, 'image-mimes', Application::IMAGE_MIMES);
$this->initialStateService->provideInitialState($this->appName, 'video-mimes', Application::VIDEO_MIMES);
$this->initialStateService->provideInitialState($this->appName, 'maps', $this->appManager->isEnabledForUser('maps') === true);
$this->initialStateService->provideInitialState($this->appName, 'recognize', $this->appManager->isEnabledForUser('recognize') === true);
$this->initialStateService->provideInitialState($this->appName, 'croppedLayout', $this->config->getUserValue($user->getUid(), Application::APP_ID, 'croppedLayout', 'false'));
$this->initialStateService->provideInitialState($this->appName, 'systemtags', $this->appManager->isEnabledForUser('systemtags') === true);
$this->initialState->provideInitialState('image-mimes', Application::IMAGE_MIMES);
$this->initialState->provideInitialState('video-mimes', Application::VIDEO_MIMES);
$this->initialState->provideInitialState('maps', $this->appManager->isEnabledForUser('maps') === true);
$this->initialState->provideInitialState('recognize', $this->appManager->isEnabledForUser('recognize') === true);
$this->initialState->provideInitialState('systemtags', $this->appManager->isEnabledForUser('systemtags') === true);

// Provide user config
foreach (array_keys(UserConfigService::DEFAULT_CONFIGS) as $key) {
$this->initialState->provideInitialState($key, $this->userConfig->getUserConfig($key));
}

$paths = [];
try {
Expand All @@ -127,7 +131,7 @@ public function index(): TemplateResponse {
$this->logger->error($e->getMessage());
}

$this->initialStateService->provideInitialState($this->appName, 'nomedia-paths', $paths);
$this->initialState->provideInitialState('nomedia-paths', $paths);

Util::addScript(Application::APP_ID, 'photos-main');
Util::addStyle(Application::APP_ID, 'icons');
Expand Down
73 changes: 73 additions & 0 deletions lib/Service/UserConfigService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Photos\Service;

use Exception;
use OCA\Photos\AppInfo\Application;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IUserSession;

class UserConfigService {
public const DEFAULT_CONFIGS = [
Copy link
Member Author

@skjnldsv skjnldsv Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could theoritecally be exposed as a capability and used straight away by the

return {
croppedLayout: croppedLayoutLocalStorage !== null
? croppedLayoutLocalStorage === 'true'
: loadState('photos', 'croppedLayout') === 'true',
photosLocation: loadState('photos', 'photosLocation'),
}
instead of having to declare them again in the front :)

'croppedLayout' => 'false',
'photosLocation' => '/Photos',
];

private IConfig $config;
private IUserSession $userSession;
private IRootFolder $rootFolder;

public function __construct(
IConfig $config,
IUserSession $userSession,
IRootFolder $rootFolder
) {
$this->config = $config;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
}

public function getUserConfig(string $key) {
if (!in_array($key, array_keys(self::DEFAULT_CONFIGS))) {
throw new Exception('Unknown user config key');
}
$user = $this->userSession->getUser();
$default = self::DEFAULT_CONFIGS[$key];
$value = $this->config->getUserValue($user->getUid(), Application::APP_ID, $key, $default);

// If the config is a path, make sure it exists
if (str_starts_with($default, '/')) {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
// If the folder does not exists, create it
if (!$userFolder->nodeExists($value)) {
$userFolder->newFolder($value);
}
}

return $value;
}
}
55 changes: 34 additions & 21 deletions src/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
</AppNavigationItem>
</template>
<template #footer>
<AppNavigationSettings :title="t('photos', 'Photos settings')">
<CroppedLayoutSettings />
</AppNavigationSettings>
<AppNavigationItem :title="t('photos', 'Photos settings')" @click="showSettings">
<Cog slot="icon" :size="20" />
</AppNavigationItem>
</template>
</AppNavigation>
<AppContent>
Expand All @@ -84,6 +84,9 @@
<!-- eslint-disable-next-line vue/no-v-html (because it's an SVG file) -->
<span class="hidden-visually" role="none" v-html="videoplaceholder" />
</AppContent>

<!-- Main settings Modal-->
<SettingsDialog :open.sync="openedSettings" />
</Content>
</template>

Expand All @@ -102,55 +105,59 @@ import CalendarToday from 'vue-material-design-icons/CalendarToday.vue'
import Tag from 'vue-material-design-icons/Tag.vue'
import MapMarker from 'vue-material-design-icons/MapMarker.vue'
import ShareVariant from 'vue-material-design-icons/ShareVariant.vue'
import AccountBoxMultipleOutline from 'vue-material-design-icons/AccountBoxMultipleOutline'
import AccountBoxMultipleOutline from 'vue-material-design-icons/AccountBoxMultipleOutline.vue'
import Cog from 'vue-material-design-icons/Cog.vue'

import Content from '@nextcloud/vue/dist/Components/Content'
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
import AppNavigationSettings from '@nextcloud/vue/dist/Components/AppNavigationSettings'
import AppContent from '@nextcloud/vue/dist/Components/AppContent.js'
import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation.js'
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem.js'
import Content from '@nextcloud/vue/dist/Components/Content.js'

import SettingsDialog from './components/Settings/SettingsDialog.vue'

import CroppedLayoutSettings from './components/Settings/CroppedLayoutSettings.vue'
import svgplaceholder from './assets/file-placeholder.svg'
import imgplaceholder from './assets/image.svg'
import videoplaceholder from './assets/video.svg'
import isMapsInstalled from './services/IsMapsInstalled.js'
import areTagsInstalled from './services/AreTagsInstalled.js'
import isMapsInstalled from './services/IsMapsInstalled.js'
import isRecognizeInstalled from './services/IsRecognizeInstalled.js'

export default {
name: 'Photos',
components: {
Content,
CroppedLayoutSettings,
AccountBoxMultipleOutline,
AppContent,
AppNavigation,
AppNavigationItem,
AppNavigationSettings,
ImageIcon,
Cog,
CalendarToday,
Camera,
VideoIcon,
FolderMultipleImage,
Content,
Folder,
Star,
CalendarToday,
Tag,
FolderMultipleImage,
ImageIcon,
MapMarker,
SettingsDialog,
ShareVariant,
AccountBoxMultipleOutline,
Star,
Tag,
VideoIcon,
},
data() {
return {
svgplaceholder,
imgplaceholder,
videoplaceholder,
areTagsInstalled,

showLocationMenuEntry: getCurrentUser() === null
? false
: getCurrentUser().isAdmin || isMapsInstalled,
showPeopleMenuEntry: getCurrentUser() === null
? false
: getCurrentUser().isAdmin || isRecognizeInstalled,

openedSettings: false,
}
},

Expand Down Expand Up @@ -180,6 +187,12 @@ export default {
navigator.serviceWorker.register(generateUrl('/apps/photos/service-worker.js'))
})
},

methods: {
showSettings() {
this.openedSettings = true
},
},
}
</script>
<style lang="scss">
Expand Down
Loading