Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: routes and icons
- don't use backend generic home route
- use 'specs' and apiSpecs
- child apis draw their icon in 16
- keep open states

Signed-off-by: Sebastien Marinier <[email protected]>
  • Loading branch information
smarinier committed Nov 26, 2024
commit 1234b524d674ba2c4c6a375b66358eb016018237
12 changes: 1 addition & 11 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'apps#index', 'url' => '/apps', 'verb' => 'GET'],
['name' => 'apps#load', 'url' => '/apps/{app}', 'verb' => 'GET'],
// The following route is there to prevent redirection to NC's general homepage
// when reloading a page in the application (If we don't add it all pages that
// don't have a route registered here redirect to NC's general homepage upon refresh)
[
'name' => 'page#index',
'url' => '/{path}',
'verb' => 'GET',
'requirements' => ['path' => '.*'],
'defaults' => ['path' => 'dummy'],
'postfix' => 'catchall',
]
['name' => 'page#view', 'url' => '/view/{app}', 'verb' => 'GET'], // handled by Vue router
],
];
8 changes: 8 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public function index(): TemplateResponse {
return new TemplateResponse(Application::APP_ID, 'main');
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function view(): TemplateResponse {
return $this->index();
}

}
14 changes: 7 additions & 7 deletions lib/Service/AppsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ public function findSupported(): array {
if (!$this->appManager->isEnabledForUser($app)) {
continue;
}
$appApis = [];
$appSpecs = [];
try {
$baseDir = $this->appManager->getAppPath($app);
$iterator = new \DirectoryIterator($baseDir);
foreach ($iterator as $file) {
if ($file->getFilename() == 'openapi.json') {
$appApis[] = $app;
$appSpecs[] = $app;
} else if (str_starts_with($file->getFilename(), 'openapi-') && str_ends_with($file->getFilename(), '.json')) {
$appApis[] = $app . '-' . substr($file->getFilename(), 8, -5);
$appSpecs[] = $app . '-' . substr($file->getFilename(), 8, -5);
}
}
} catch (AppPathNotFoundException) {
}
if (!empty($appApis)) {
if ($appSpecs !== []) {
$appInfo = $this->appManager->getAppInfo($app);
$apiInfo =[
$apiInfo = [
'id' => $app,
'apis' => $appApis,
'specs' => $appSpecs,
'name' => $appInfo['name'],
'version' => $appInfo['version'],
'always_enabled' => in_array($app, $always),
Expand All @@ -62,7 +62,7 @@ public function findSupported(): array {
if (file_exists(\OC::$SERVERROOT . '/core/openapi.json')) {
array_unshift($apis, [
'id' => 'core',
'apis' => ['core'],
'specs' => ['core'],
'name' => 'Core Nextcloud API',
'version' => implode('.', \OCP\Util::getVersion()),
'always_enabled' => true,
Expand Down
31 changes: 23 additions & 8 deletions src/ApiNavigationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
:key="app.id"
allow-collapse
:name="app.name"
:open="isSelectedChild($route.params.appid, app)"
:to="{path: `/view/${app.id}`}">
:open="isSelectedChild($route.params.appid, app) || isManuallyOpened(app.id)"
:to="{path: `/view/${app.id}`}"
@update:open="(open) => onOpen(app.id, open)">
<template #icon>
<AppIcon v-if="app.icon_url"
:href="app.icon_url" />
Expand All @@ -14,7 +15,15 @@
<NcAppNavigationItem v-for="child in childApis(app)"
:key="child.id"
:name="child.name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should strip the app id prefix so that it's just full and not provisioning_api-full. I think this would look a bit better.

:to="{path: `/view/${child.id}`}" />
:to="{path: `/view/${child.id}`}">
<template #icon>
<AppIcon v-if="app.icon_url"
size="16"
:href="app.icon_url" />
<ApiIcon v-else
size="16" />
</template>
</NcAppNavigationItem>
</NcAppNavigationItem>
</NcAppNavigationList>
</template>
Expand Down Expand Up @@ -42,31 +51,37 @@ export default {
},
computed: {
apps() {
const apps = store.apps
return store.apps
.filter(app => app.always_enabled === this.alwaysEnabled)
.sort(function(a, b) {
// core nextcloud always first
if (a.id === 'core') return -1
if (b.id === 'core') return 1
return OC.Util.naturalSortCompare(a.name, b.name)
})
return apps
},
},
methods: {
isSelectedChild(appId, app) {
if (appId === app.id) {
return false
}
return app.apis.indexOf(appId) >= 0
return app.specs.indexOf(appId) >= 0
},
childApis(app) {
if (app.apis === undefined || app.apis.length === 1) {
if (app.specs === undefined || app.specs.length === 1) {
return []
}
return app.apis.filter(id => id !== app.id)
return app.specs
.filter(id => id !== app.id)
.map(cid => ({ id: cid, name: cid }))
},
isManuallyOpened(appId) {
return store.isAppOpened(appId)
},
onOpen(appId, open) {
store.appOpen(appId, open)
},
},
}
</script>
12 changes: 6 additions & 6 deletions src/AppIcon.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<template>
<svg width="24"
height="24"
viewBox="0 0 24 24">
<svg :width="size"
:height="size"
:viewBox="`0 0 ${size} ${size}`">
<image x="0"
y="0"
width="24"
height="24"
preserveAspectRatio="xMinYMin meet"
:width="size"
:height="size"
:xlink:href="href"
class="app-icon" />
</svg>
Expand All @@ -17,6 +16,7 @@ export default {
name: 'AppIcon',
props: {
href: { type: String, default: '' },
size: { type: Number, default: 24 },
},
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/Welcome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<template #icon>
<OpenInNew :size="20" />
</template>
Nextcloud OpenApi extractor
Nextcloud openapi-extractor
</NcActionLink>
</NcActions>
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useAppsStore = defineStore('ocs-api-viewer-apps', {
state: () => ({
loading: true,
apps: [],
appOpened: [],
}),

actions: {
Expand All @@ -41,5 +42,11 @@ export const useAppsStore = defineStore('ocs-api-viewer-apps', {
getAppById(appId) {
return this.apps.find(({ id }) => id === appId) ?? null
},
isAppOpened(appId) {
return this.appOpened[appId] ?? false
},
appOpen(appId, open) {
this.appOpened[appId] = open
},
},
})
Loading