Skip to content

Commit

Permalink
Remember the UI that was last selected via the application switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Dec 21, 2021
1 parent 7647b32 commit 37b5650
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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)
cp -R packages/web-integration-oc10/lib $(dist_dir)

.PHONY: ocx-app-bundle
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([]);
}
}
31 changes: 30 additions & 1 deletion packages/web-runtime/src/components/ApplicationsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
>
<ul class="uk-grid-small uk-text-center" uk-grid>
<li v-for="(n, nid) in menuItems" :key="`apps-menu-${nid}`" class="uk-width-1-3">
<a v-if="n.url" key="apps-menu-external-link" :target="n.target" :href="n.url">
<a
v-if="n.url"
key="apps-menu-external-link"
:target="n.target"
:href="n.url"
@click="clickApp(n)"
>
<oc-icon :name="n.iconMaterial" size="xlarge" />
<span class="uk-display-block" v-text="$gettext(n.title)" />
</a>
Expand All @@ -39,6 +45,7 @@
<script>
import NavigationMixin from '../mixins/navigationMixin'
import UiKit from 'uikit'
import { mapGetters } from 'vuex'
export default {
mixins: [NavigationMixin],
Expand All @@ -50,6 +57,7 @@ export default {
}
},
computed: {
...mapGetters(['configuration', 'getToken']),
menuItems() {
return this.navigation_getMenuItems([null, 'apps', 'appSwitcher'])
},
Expand Down Expand Up @@ -84,6 +92,27 @@ export default {
},
focusMenuButton() {
this.$refs.menubutton.$el.focus()
},
async clickApp(appEntry) {
// @TODO use id or similar
if (appEntry.iconMaterial === 'switch_ui') {
await this.setClassicUIDefault()
}
},
setClassicUIDefault() {
const endpoint = new URL(this.configuration.server || window.location.origin)
endpoint.pathname =
endpoint.pathname.replace(/\/$/, '') + '/index.php/apps/web/settings/default'
const headers = new Headers()
headers.append('Authorization', 'Bearer ' + this.getToken)
headers.append('X-Requested-With', 'XMLHttpRequest')
return fetch(endpoint.href, {
headers,
method: 'POST',
body: JSON.stringify({ isDefault: false })
})
}
}
}
Expand Down

0 comments on commit 37b5650

Please sign in to comment.