Skip to content

Commit

Permalink
Merge pull request #3806 from owncloud/fix-settings
Browse files Browse the repository at this point in the history
Fix settings
  • Loading branch information
kulmann authored Aug 19, 2020
2 parents 0fc6490 + bc449ba commit f76c33b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 53 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/adapt-to-settings-data-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Change: Adapt to new ocis-settings data model

ocis-settings introduced UUIDs and less verbose endpoint and message type names. This PR adjusts phoenix accordingly.

https://github.com/owncloud/phoenix/pull/3806
https://github.com/owncloud/owncloud-sdk/pull/520
https://github.com/owncloud/ocis-settings/pull/46
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"npm-run-all": "^4.1.5",
"oidc-client": "^1.9.1",
"owncloud-design-system": "^1.9.0",
"owncloud-sdk": "^1.0.0-728",
"owncloud-sdk": "^1.0.0-740",
"p-limit": "^2.2.1",
"p-queue": "^6.1.1",
"parse-json": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/Phoenix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default {
'activeMessages',
'capabilities',
'apps',
'getSettingsValueByIdentifier',
'getSettingsValue',
'getNavItems',
'getExtensionsWithNavItems'
]),
Expand Down Expand Up @@ -190,10 +190,10 @@ export default {
},
selectedLanguage() {
return this.getSettingsValueByIdentifier({
return this.getSettingsValue({
extension: 'ocis-accounts',
bundleKey: 'profile',
settingKey: 'language'
bundle: 'profile',
setting: 'language'
})
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/phoenix.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function requireError (err) {

// Loads apps from external servers
if (config.external_apps) {
config.external_apps.map(app => apps.push(app.path))
config.external_apps.forEach(app => apps.push(app.path))
}

// provide global config object
Expand Down
9 changes: 5 additions & 4 deletions src/store/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const actions = {
* @param {Object} config Config from config.json which can overwrite local config from AppInfo
*/
loadExternalAppConfig({ dispatch }, { app, config }) {
config.external_apps.map(extension => {
config.external_apps.forEach(extension => {
// Check if app is loaded from external server
// Extension id = id from external apps array
// App id = id specified in AppInfo
Expand Down Expand Up @@ -162,15 +162,16 @@ const getters = {
if (!ext) {
return []
}
ext.map(e => {
ext.forEach(e => {
if (e.version === 3) {
return e
}
// enhance App Chooser with App Name as label
e.name = state.meta[e.app].name
// if no icon for this filetype extension, choose the app icon
if (!e.icon) e.icon = state.meta[e.app].icon
return e
if (!e.icon) {
e.icon = state.meta[e.app].icon
}
})
return ext
}
Expand Down
69 changes: 32 additions & 37 deletions src/store/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import keyBy from 'lodash/keyBy'
import assign from 'lodash/assign'
import findKey from 'lodash/findKey'
import isNil from 'lodash/isNil'
import isEqual from 'lodash/isEqual'

const state = {
settingsValues: null
}
Expand Down Expand Up @@ -25,41 +31,44 @@ const mutations = {
if (settingsValues === null) {
state.settingsValues = null
} else {
const map = new Map()
Array.from(settingsValues).forEach(value => applySettingsValueToMap(value, map))
state.settingsValues = map
state.settingsValues = keyBy(settingsValues, 'value.id')
}
},
SET_SETTINGS_VALUE(state, settingsValue) {
const map = new Map(state.settingsValues)
applySettingsValueToMap(settingsValue, map)
state.settingsValues = map
state.settingsValues = assign({}, state.settingsValues, {
[settingsValue.value.id]: settingsValue
})
}
}

const getters = {
settingsValuesLoaded: state => {
return state.settingsValues !== null
},
hasSettingsValue: (state, getters) => ({ extension, bundleKey, settingKey }) => {
return getters.getSettingsValueByIdentifier({ extension, bundleKey, settingKey }) !== null
// calling this getter requires either having the `settingId` or all three other params
hasSettingsValue: (state, getters) => ({ settingId, extension, bundle, setting }) => {
return getters.getSettingsValue({ settingId, extension, bundle, setting }) !== null
},
getSettingsValueByIdentifier: (state, getters) => ({ extension, bundleKey, settingKey }) => {
if (
getters.settingsValuesLoaded &&
state.settingsValues.has(extension) &&
state.settingsValues.get(extension).has(bundleKey) &&
state.settingsValues
.get(extension)
.get(bundleKey)
.has(settingKey)
) {
return state.settingsValues
.get(extension)
.get(bundleKey)
.get(settingKey)
// calling this getter requires either having the `settingId` or all three other params
getSettingsValue: (state, getters) => ({ settingId, extension, bundle, setting }) => {
if (!getters.settingsValuesLoaded) {
return null
}
if (settingId) {
const key = findKey(
state.settingsValues,
settingsValue => settingsValue.value.settingId === settingId
)
return isNil(key) ? null : state.settingsValues[key].value
}
return null
const key = findKey(state.settingsValues, settingsValue =>
isEqual(settingsValue.identifier, {
extension,
bundle,
setting
})
)
return isNil(key) ? null : state.settingsValues[key].value
}
}

Expand All @@ -69,17 +78,3 @@ export default {
mutations,
getters
}

function applySettingsValueToMap(settingsValue, map) {
if (!map.has(settingsValue.identifier.extension)) {
map.set(settingsValue.identifier.extension, new Map())
}
if (!map.get(settingsValue.identifier.extension).has(settingsValue.identifier.bundleKey)) {
map.get(settingsValue.identifier.extension).set(settingsValue.identifier.bundleKey, new Map())
}
map
.get(settingsValue.identifier.extension)
.get(settingsValue.identifier.bundleKey)
.set(settingsValue.identifier.settingKey, settingsValue)
return map
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2980,9 +2980,9 @@ data-uri-to-buffer@1:
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-1.2.0.tgz#77163ea9c20d8641b4707e8f18abdf9a78f34835"
integrity sha512-vKQ9DTQPN1FLYiiEEOQ6IBGFqvjCa5rSK3cWMy/Nespm5d/x3dGFT9UBZnkLxCwua/IXBi2TYnwTEpsOvhC4UQ==

"davclient.js@https://github.com/owncloud/davclient.js.git":
"davclient.js@git+https://github.com/owncloud/davclient.js.git":
version "0.2.1"
resolved "https://github.com/owncloud/davclient.js.git#bf19f590451b3c0658913568053ec7f300f7dfc1"
resolved "git+https://github.com/owncloud/davclient.js.git#bf19f590451b3c0658913568053ec7f300f7dfc1"

de-indent@^1.0.2:
version "1.0.2"
Expand Down Expand Up @@ -6919,10 +6919,10 @@ owncloud-design-system@^1.9.0:
webfontloader "^1.6.28"
weekstart "^1.0.0"

owncloud-sdk@^1.0.0-728:
version "1.0.0-728"
resolved "https://registry.yarnpkg.com/owncloud-sdk/-/owncloud-sdk-1.0.0-728.tgz#69f35830625e6a213e6e49a5eae5a925a688d4f0"
integrity sha512-XQQIlV15mCUd2k4d0/+QSS0PCHYtGLkvUA/BzO4P7TPhVh/RmnLLxTgL4XSPM2MTQCk0C0geXK3C6bqhdm5QWQ==
owncloud-sdk@^1.0.0-740:
version "1.0.0-740"
resolved "https://registry.yarnpkg.com/owncloud-sdk/-/owncloud-sdk-1.0.0-740.tgz#cfa6306d3ec28f4a4dd288fd9cdc2ed1e45747f0"
integrity sha512-iQ9HW+P6+4O3vhh8oU7UQlGYTFgyKvdA3krEJAwW4+iKnKxNQ9BxIl8JNcv1NxNOILf/PVkJjFDz/+vcHuhmrw==
dependencies:
axios "^0.19.2"
browser-request "^0.3.3"
Expand Down

0 comments on commit f76c33b

Please sign in to comment.