Skip to content

Commit

Permalink
style: cleanup and remove duplicated code
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jun 28, 2023
1 parent 0f77d3e commit 7a7fb0d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 39 deletions.
12 changes: 0 additions & 12 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\Util;
use Psr\Log\LoggerInterface;

Expand All @@ -66,13 +64,8 @@ class PageController extends Controller {
private ICacheFactory $cacheFactory;
private IL10N $l10n;
private ICache $nomediaPathsCache;
private ICache $tagCountsCache;
private LoggerInterface $logger;

private ISystemTagObjectMapper $tagObjectMapper;

private ISystemTagManager $tagManager;

public function __construct(
IRequest $request,
IAppManager $appManager,
Expand All @@ -83,8 +76,6 @@ public function __construct(
IRootFolder $rootFolder,
ICacheFactory $cacheFactory,
LoggerInterface $logger,
ISystemTagObjectMapper $tagObjectMapper,
ISystemTagManager $tagManager,
IL10N $l10n
) {
parent::__construct(Application::APP_ID, $request);
Expand All @@ -97,10 +88,7 @@ public function __construct(
$this->rootFolder = $rootFolder;
$this->cacheFactory = $cacheFactory;
$this->nomediaPathsCache = $this->cacheFactory->createLocal('photos:nomedia-paths');
$this->tagCountsCache = $this->cacheFactory->createLocal('photos:tag-counts');
$this->logger = $logger;
$this->tagObjectMapper = $tagObjectMapper;
$this->tagManager = $tagManager;
$this->l10n = $l10n;
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/Settings/PhotosLocationSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ import UserConfig from '../../mixins/UserConfig.js'
export default {
name: 'PhotosLocationSettings',
mixins: [
UserConfig,
],
components: {
NcButton,
NcTextField,
Folder,
},
mixins: [
UserConfig,
],
methods: {
debounceSelectPhotosFolder: debounce(function() {
this.selectPhotosFolder()
Expand Down
38 changes: 15 additions & 23 deletions src/utils/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,7 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
* @param {object} obj - object to flatten and format.
*/
function genFileInfo(obj) {
const fileInfo = Object.entries(obj).reduce((fileInfo, [key, data]) => {
// flatten object if any
if (!!data && typeof data === 'object' && !Array.isArray(data)) {
return { ...fileInfo, ...genFileInfo(data) }
}

// format key and add it to the fileInfo
switch (data) {
case 'false':
return { ...fileInfo, [camelcase(key)]: false }
case 'true':
return { ...fileInfo, [camelcase(key)]: true }
default:
return { ...fileInfo, [camelcase(key)]: isNumber(data) ? Number(data) : data }
}
}, {})
const fileInfo = flattenAndFormatObject(obj, genFileInfo)

if (fileInfo.filename) {
// Adding context
Expand All @@ -132,24 +117,31 @@ function genFileInfo(obj) {
* @param {object} obj - object to flatten and format.
*/
function extractTagInfo(obj) {
const tagInfo = Object.entries(obj).reduce((tagInfo, [key, data]) => {
return flattenAndFormatObject(obj, extractTagInfo)
}

/**
*
* @param obj
* @param callback
*/
function flattenAndFormatObject(obj, callback) {
return Object.entries(obj).reduce((resultObj, [key, data]) => {
// flatten object if any
if (!!data && typeof data === 'object' && !Array.isArray(data)) {
return { ...tagInfo, ...extractTagInfo(data) }
return { ...resultObj, ...callback(data) }
}

// format key and add it to the tagInfo
switch (data) {
case 'false':
return { ...tagInfo, [camelcase(key)]: false }
return { ...resultObj, [camelcase(key)]: false }
case 'true':
return { ...tagInfo, [camelcase(key)]: true }
return { ...resultObj, [camelcase(key)]: true }
default:
return { ...tagInfo, [camelcase(key)]: isNumber(data) ? Number(data) : data }
return { ...resultObj, [camelcase(key)]: isNumber(data) ? Number(data) : data }
}
}, {})

return tagInfo
}

export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo, extractTagInfo }

0 comments on commit 7a7fb0d

Please sign in to comment.