From 557e0479cc3eb93e0bdc9cee0957eedc79a06557 Mon Sep 17 00:00:00 2001 From: Hernan Lopes Date: Wed, 3 Mar 2021 05:06:14 +0100 Subject: [PATCH] feat(api): api docs component --- src/app/dev/dev.component.html | 7 +- src/app/rmm.ts | 3 + src/app/rmm/docs.ts | 39 +++++ src/app/runbox-components/runbox-api-docs.ts | 135 ++++++++++++++++++ .../runbox-component.module.ts | 5 + 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 src/app/rmm/docs.ts create mode 100644 src/app/runbox-components/runbox-api-docs.ts diff --git a/src/app/dev/dev.component.html b/src/app/dev/dev.component.html index db67b44a2..8ef316b1d 100644 --- a/src/app/dev/dev.component.html +++ b/src/app/dev/dev.component.html @@ -2,7 +2,7 @@ .row { display: flex; flex-direction: row; - flex-wrap: wrap; + flex-wrap: nowrap; } .column { @@ -49,11 +49,16 @@

Components

Dynamic + + API +
+ + diff --git a/src/app/rmm.ts b/src/app/rmm.ts index 8050cd9ae..7caa144eb 100644 --- a/src/app/rmm.ts +++ b/src/app/rmm.ts @@ -25,6 +25,7 @@ import { Alias } from './rmm/alias'; import { Me } from './rmm/me'; import { RunboxDomain } from './rmm/runbox_domain'; import { AccountSecurity } from './rmm/account-security'; +import { Docs } from './rmm/docs'; import { MatSnackBar } from '@angular/material/snack-bar'; @Injectable({ @@ -39,6 +40,7 @@ export class RMM { public email: Email; public runbox_domain: RunboxDomain; public account_security: AccountSecurity; + public docs: Docs; constructor( public http: HttpClient, public snackBar: MatSnackBar, @@ -50,6 +52,7 @@ export class RMM { this.runbox_domain = new RunboxDomain(this); this.email = new Email(this); this.account_security = new AccountSecurity(this); + this.docs = new Docs(this); } public show_error ( message, action ) { diff --git a/src/app/rmm/docs.ts b/src/app/rmm/docs.ts new file mode 100644 index 000000000..93a1ee700 --- /dev/null +++ b/src/app/rmm/docs.ts @@ -0,0 +1,39 @@ +// --------- BEGIN RUNBOX LICENSE --------- +// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com). +// +// This file is part of Runbox 7. +// +// Runbox 7 is free software: You can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation, either version 3 of the License, or (at your +// option) any later version. +// +// Runbox 7 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Runbox 7. If not, see . +// ---------- END RUNBOX LICENSE ---------- +import { timeout, share } from 'rxjs/operators'; +import { Observable } from 'rxjs'; +import { RMM } from '../rmm'; + +export class Docs { + constructor( + public app: RMM, + ) { + } + load_docs(): Observable { + const req = this.app.ua.http.get('/_js/docs.json').pipe(timeout(60000), share()); + req.subscribe( + data => { + }, + error => { + return this.app.show_error('Could not load /_js/docs.json.', 'Dismiss'); + } + ); + return req; + } +} diff --git a/src/app/runbox-components/runbox-api-docs.ts b/src/app/runbox-components/runbox-api-docs.ts new file mode 100644 index 000000000..c766d5cb5 --- /dev/null +++ b/src/app/runbox-components/runbox-api-docs.ts @@ -0,0 +1,135 @@ +// --------- BEGIN RUNBOX LICENSE --------- +// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com). +// +// This file is part of Runbox 7. +// +// Runbox 7 is free software: You can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the +// Free Software Foundation, either version 3 of the License, or (at your +// option) any later version. +// +// Runbox 7 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 +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Runbox 7. If not, see . +// ---------- END RUNBOX LICENSE ---------- +import { + Component, + OnInit +} from '@angular/core'; +import { RMM } from '../rmm'; +import 'rxjs/add/operator/toPromise'; + +@Component({ + selector: 'app-runbox-api-docs', + styles: [` + .docs-container { + display: flex; + flex-grow: 1; + } + .docs-container .row { + display: flex; + flex-direction: row; + flex-grow: 1; + } + .docs-container .col { + display: flex; + flex-direction: column; + flex-grow: 1; + } + `], + template: ` +
+
+
+
+
+ +
+ {{section}} + +
+
+
+
+
+
+ + + +
+

{{docs.sections[section][subsection].section}} > {{docs.sections[section][subsection].title}}

+
+
+
+

Description: {{docs.sections[section][subsection].details}}

+

Url: https://runbox.com{{docs.sections[section][subsection].request.url}}

+

Method: {{docs.sections[section][subsection].request.method}}

+ +
+
+

Request

+

Headers: {{docs.sections[section][subsection].request.headers | json}}

+

Content: {{docs.sections[section][subsection].request.content}}

+ +
+
+

Response

+

Headers: {{docs.sections[section][subsection].response.headers | json}}

+

Content: {{docs.sections[section][subsection].response.content}}

+
+
+
+
+
+
+
+
+
+
+
+
+ ` +}) + +export class RunboxApiDocsComponent implements OnInit { + docs_url: '/_js/docs.json'; + docs: any; + section: any; + sections: any; + subsections: any; + public tab_index: any; + constructor( + public rmm: RMM, + ) { + } + + ngOnInit() { + this.load_docs(); + } + + sort_alphanumeric(a, b) { + if ( a < b ) { return -1; } + if ( a > b ) { return 1; } + return 0; + } + + load_docs() { + const req = this.rmm.docs.load_docs(); + req.toPromise().then( (data) => { + this.docs = data; + this.sections = Object.keys( this.docs.sections ).sort( this.sort_alphanumeric ); + this.open_section(this.sections[0]); + }); + } + + open_section(section) { + this.section = section; + this.subsections = Object.keys(this.docs.sections[this.section]).sort( this.sort_alphanumeric ); + setTimeout( () => { this.tab_index = 0; }, 200 ); + } +} + diff --git a/src/app/runbox-components/runbox-component.module.ts b/src/app/runbox-components/runbox-component.module.ts index 6af07775f..54b8b382a 100644 --- a/src/app/runbox-components/runbox-component.module.ts +++ b/src/app/runbox-components/runbox-component.module.ts @@ -36,6 +36,7 @@ import { MatMenuModule } from '@angular/material/menu'; import { MatGridListModule } from '@angular/material/grid-list'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatTableModule } from '@angular/material/table'; +import { MatTabsModule } from '@angular/material/tabs'; import { RunboxIntroComponent } from '../runbox-components/runbox-intro'; import { RunboxListComponent } from '../runbox-components/runbox-list'; import { RunboxContainerComponent } from '../runbox-components/runbox-container'; @@ -43,6 +44,7 @@ import { RunboxSectionComponent } from '../runbox-components/runbox-section'; import { RunboxSlideToggleComponent } from '../runbox-components/runbox-slide-toggle'; import { RunboxTimerComponent } from '../runbox-components/runbox-timer'; import { RunboxDynamicComponent } from '../runbox-components/runbox-dynamic'; +import { RunboxApiDocsComponent } from '../runbox-components/runbox-api-docs'; import { RunboxDynamicBuilderComponent } from './runbox-dynamic-builder'; @NgModule({ @@ -55,6 +57,7 @@ import { RunboxDynamicBuilderComponent } from './runbox-dynamic-builder'; RunboxTimerComponent, RunboxDynamicComponent, RunboxDynamicBuilderComponent, + RunboxApiDocsComponent, ], imports: [ CommonModule, @@ -74,6 +77,7 @@ import { RunboxDynamicBuilderComponent } from './runbox-dynamic-builder'; MatToolbarModule, MatTooltipModule, MatTableModule, + MatTabsModule, MenuModule, ], exports: [ @@ -85,6 +89,7 @@ import { RunboxDynamicBuilderComponent } from './runbox-dynamic-builder'; RunboxTimerComponent, RunboxDynamicComponent, RunboxDynamicBuilderComponent, + RunboxApiDocsComponent, ], entryComponents: [ ],