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 4 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 -R packages/web-integration-oc10/js $(dist_dir)
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
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
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');
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* @author Jannik Stehle <jstehle@owncloud.com>
* @author Jan Ackermann <jackermann@owncloud.com>
*
* @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([]);
}
}
26 changes: 26 additions & 0 deletions packages/web-runtime/src/components/Topbar/ApplicationsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
appearance="raw"
:class="{ 'oc-background-primary-gradient': n.active }"
:variation="n.active ? 'inverse' : 'passive'"
@click="clickApp(n)"
>
<span class="icon-box">
<oc-icon :name="n.icon" />
Expand All @@ -48,6 +49,8 @@
</template>

<script>
import { mapGetters } from 'vuex'

export default {
props: {
applicationsList: {
Expand All @@ -57,6 +60,8 @@ export default {
}
},
computed: {
...mapGetters(['configuration', 'getToken']),
JammingBen marked this conversation as resolved.
Show resolved Hide resolved

applicationSwitcherLabel() {
return this.$gettext('Application Switcher')
}
Expand All @@ -66,6 +71,27 @@ 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.iconMaterial === 'switch_ui') {
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
await this.setClassicUIDefault()
}
},
setClassicUIDefault() {
const endpoint = new URL(this.configuration.server || window.location.origin)
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
endpoint.pathname =
endpoint.pathname.replace(/\/$/, '') + '/index.php/apps/web/settings/default'
const headers = new Headers()
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
headers.append('Authorization', 'Bearer ' + this.getToken)
headers.append('X-Requested-With', 'XMLHttpRequest')
return fetch(endpoint.href, {
headers,
method: 'POST',
body: JSON.stringify({ 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/**