Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember the UI that was last selected via the application switcher #6173

Merged
merged 6 commits into from
Sep 8, 2022
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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
requirejs: false
},
plugins: ['jest', 'unused-imports'],
ignorePatterns: ['packages/web-integration-oc10/js'],
overrides: [
{
files: ['**/*.vue'],
Expand Down
1 change: 1 addition & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ endif
.PHONY: ocx-app-config
ocx-app-config:
cp -R packages/web-integration-oc10/appinfo $(dist_dir)
cp packages/web-integration-oc10/js/* $(dist_dir)/js
cp -R packages/web-integration-oc10/lib $(dist_dir)

.PHONY: ocx-app-bundle
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-remember-selected-ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Remember the UI that was last selected via the application switcher

With this change, ownCloud will remember the UI that was last selected via the application switcher. This only works when using ownCloud 10 as backend.

https://github.com/owncloud/web/pull/6173
https://github.com/owncloud/enterprise/issues/4694
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ services:
- ./packages/web-integration-oc10/lib:/mnt/data/apps/web/lib
- ./dist/css:/mnt/data/apps/web/css
- ./dist/img:/mnt/data/apps/web/img
- ./dist/js:/mnt/data/apps/web/js
- ./dist/js:/mnt/data/apps/web/js/
- ./packages/web-integration-oc10/js/app.js:/mnt/data/apps/web/js/app.js
- ./dist/themes:/mnt/data/apps/web/themes
- ./dist/icons:/mnt/data/apps/web/icons
- ./dist/fonts:/mnt/data/apps/web/fonts
Expand Down
1 change: 1 addition & 0 deletions packages/web-integration-oc10/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
*/

$app = new OCA\Web\Application();
$app->boot();
1 change: 1 addition & 0 deletions packages/web-integration-oc10/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'routes' => [
['name' => 'Index#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'],
['name' => 'Settings#setWebDefaultConfig', 'url' => '/settings/default', 'verb' => 'POST'],
[
'name' => 'Files#getFile',
'url' => '/{path}',
Expand Down
7 changes: 7 additions & 0 deletions packages/web-integration-oc10/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$(document).ready(function () {
$('#apps')
.find('li[data-id=web]')
.click(function () {
$.post(OC.generateUrl('/apps/web/settings/default'), { isDefault: true })
})
})
5 changes: 5 additions & 0 deletions packages/web-integration-oc10/lib/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\Web;

use OCP\AppFramework\App;
use OCP\Util;

class Application extends App {

Expand All @@ -33,4 +34,8 @@ class Application extends App {
public function __construct(array $urlParams = []) {
parent::__construct(Application::APPID, $urlParams);
}

public function boot(): void {
Util::addScript(Application::APPID, 'app');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* @author Jannik Stehle <[email protected]>
* @author Jan Ackermann <[email protected]>
*
* @copyright Copyright (c) 2021, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Web\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;

/**
* Class SettingsController
*
* @package OCA\Web\Controller
*/
class SettingsController extends Controller {

/**
* @var IConfig
*/
private $config;

/**
* @var IUserSession
*/
private $userSession;

/**
* @param string $appName
* @param IRequest $request an instance of the request
* @param IUserSession $userSession
* @param IConfig $config
*/
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
IConfig $config
) {
parent::__construct($appName, $request);
$this->config = $config;
$this->userSession = $userSession;
}

/**
* Set the web default config.
*
* @NoAdminRequired
*
* @return JSONResponse
*/
public function setWebDefaultConfig() {
$value = \filter_var($this->request->getParam('isDefault'), FILTER_VALIDATE_BOOLEAN);
$user = $this->userSession->getUser();
$configToSet = $value === true ? 'web' : null;
if (!$configToSet) {
$this->config->deleteUserValue($user->getUID(), 'core', 'defaultapp');
} else {
$this->config->setUserValue($user->getUID(), 'core', 'defaultapp', $configToSet);
}

return new JSONResponse([]);
}
}
24 changes: 23 additions & 1 deletion packages/web-runtime/src/components/Topbar/ApplicationsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
close-on-click
>
<oc-list class="applications-list">
<li v-for="(n, nid) in applicationsList" :key="`apps-menu-${nid}`">
<li v-for="(n, nid) in applicationsList" :key="`apps-menu-${nid}`" @click="clickApp(n)">
<oc-button
:key="n.url ? 'apps-menu-external-link' : 'apps-menu-internal-link'"
:type="n.url ? 'a' : 'router-link'"
Expand All @@ -48,6 +48,10 @@
</template>

<script>
import { clientService } from 'web-pkg/src/services'
import { configurationManager } from 'web-pkg/src/configuration'
import { mapGetters } from 'vuex'

export default {
props: {
applicationsList: {
Expand All @@ -57,6 +61,8 @@ export default {
}
},
computed: {
...mapGetters('runtime/auth', ['accessToken']),

applicationSwitcherLabel() {
return this.$gettext('Application Switcher')
}
Expand All @@ -66,6 +72,22 @@ export default {
onHidden: () => this.$refs.menubutton.$el.focus(),
onShown: () => this.$refs.menu.$el.querySelector('a:first-of-type').focus()
})
},
methods: {
async clickApp(appEntry) {
// @TODO use id or similar
if (appEntry.url?.endsWith('/apps/files')) {
await this.setClassicUIDefault()
}
},
setClassicUIDefault() {
const endpoint = new URL(configurationManager.serverUrl)
endpoint.pathname =
endpoint.pathname.replace(/\/$/, '') + '/index.php/apps/web/settings/default'

const httpClient = clientService.httpAuthenticated(this.accessToken)
return httpClient.post(endpoint.href, { isDefault: false })
}
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ sonar.pullrequest.key=${env.SONAR_PULL_REQUEST_KEY}
sonar.javascript.lcov.reportPaths=coverage/lcov.info

# Exclude files
sonar.exclusions=docs/**,node_modules/**,deployments/**,**/tests/**,__mocks__/**,__fixtures__/**,dist/**,changelog/**,config/**,docker/**,release/**,**/package.json,package.json,rollup.config.js,nightwatch.conf.js,Makefile,Makefile.release,CHANGELOG.md,README.md,packages/web-client/src/generated/**
sonar.exclusions=docs/**,node_modules/**,deployments/**,**/tests/**,__mocks__/**,__fixtures__/**,dist/**,changelog/**,config/**,docker/**,release/**,**/package.json,package.json,rollup.config.js,nightwatch.conf.js,Makefile,Makefile.release,CHANGELOG.md,README.md,packages/web-client/src/generated/**,packages/web-integration-oc10/**