Skip to content

Commit

Permalink
Merge pull request #1 from tmunzer/2.0.a
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
tmunzer authored Oct 8, 2021
2 parents 09ab290 + eddfedf commit cadd041
Show file tree
Hide file tree
Showing 32 changed files with 1,601 additions and 1,002 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compile-hero.disable-compile-files-on-did-save-code": false,
"python.pythonPath": "/usr/local/bin/python3"
}
1 change: 1 addition & 0 deletions api.json

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions chrome_ext_convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import json
import shutil

js_path = "./mist_openapi/Mist.openapi.json"
res_path ="./api.json"
js_chrome = {
"paths":{},
"components": {}
}



def process_specs(specs):
for verb in specs:
if "responses" in specs[verb]:
del specs[verb]["responses"]
if "summary" in specs[verb]:
del specs[verb]["summary"]
if "requestBody" in specs[verb]:
del specs[verb]["requestBody"]
return specs

def process_sub(parent_path: dict, splitted_path: list, specs: dict):
#pp {}
current_path = splitted_path[0] # api
splitted_path = splitted_path[1:] # [v1, orgs, ...]
# pp {api: {}}}
if len(splitted_path)>0:
if not current_path in parent_path:
parent_path[current_path] = {}
if not "paths" in parent_path[current_path]:
parent_path[current_path]["paths"] = {}
parent_path[current_path]["paths"]= process_sub(parent_path[current_path]["paths"], splitted_path, specs)

else:
parent_path[current_path] = {"specs": process_specs(specs)}
return parent_path



### entry point
# open file
with open(js_path, 'r') as js:
js_data = json.loads(js.read())

# loop on each path from the open api spec
for path in js_data["paths"]:
# split the path to create the JSON levels
splitted_path = path.split("/")[1:]
specs = js_data["paths"][path]
js_chrome["paths"] = process_sub(js_chrome["paths"], splitted_path, specs)


js_chrome["components"]["parameters"] = js_data["components"]["parameters"]

with open(res_path, "w") as f:
json.dump(js_chrome, f)

shutil.copy("./api.json", "./src/angular/src/assets/api.json")
6 changes: 6 additions & 0 deletions gen_api_struct.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd mist_openapi
git pull
cd ..
python3 ./chrome_ext_convert.py
2 changes: 1 addition & 1 deletion mist_openapi
Submodule mist_openapi updated from 349b4c to ec7212
1 change: 1 addition & 0 deletions src/angular/src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ button.bottom {
display: flex;
padding: 0.5em;
align-items: center;
cursor: pointer;
}

button.bottom:not(.selected):hover {
Expand Down
8 changes: 7 additions & 1 deletion src/angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ApiComponent } from './pages/api/api.component';
import { ApiManageComponent } from './pages/api/manage/manage.component';
import { ApiDjangoComponent } from './pages/api/django/django.component';
import { AccountComponent } from './pages/account/account.component';
import { AccountManageComponent } from './pages/account/manage/manage.component';
import { AccountCreateComponent } from './pages/account/create/create.component'
Expand All @@ -13,7 +15,11 @@ import { AccountCreateOrgComponent } from './pages/account/create_org/create_org
import { AboutComponent } from './pages/about/about.component'

@NgModule({
declarations: [AppComponent, ApiComponent, AccountComponent, AccountManageComponent, AccountCreateComponent, AccountManageOrgComponent, AccountCreateOrgComponent, AboutComponent],
declarations: [
AppComponent,
ApiComponent, ApiManageComponent, ApiDjangoComponent,
AccountComponent, AccountManageComponent, AccountCreateComponent, AccountManageOrgComponent, AccountCreateOrgComponent,
AboutComponent],
imports: [BrowserModule, AppRoutingModule, FormsModule, HttpClientModule],
bootstrap: [AppComponent]
})
Expand Down
4 changes: 2 additions & 2 deletions src/angular/src/app/pages/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ <h2>Extension information</h2>
<div>Unknown</div>
<img src="assets/question.svg" alt="unknow version">
</div>
<div class="version-uptodate" *ngIf="last_version && current_version == last_version">
<div class="version-uptodate" *ngIf="last_version && up_to_date">
<div>You have the lastest Version</div>
</div>
<div class="version-newversion" *ngIf="last_version && current_version != last_version">
<div class="version-newversion" *ngIf="last_version && !up_to_date">
<div>New version available ({{last_version}})</div>
<button class="download" (click)="openTab('download_url')">
<div>Downlaod</div>
Expand Down
2 changes: 2 additions & 0 deletions src/angular/src/app/pages/about/about.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ button.links:enabled {
color: white;
box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.06) 0px 1px 2px 0px;
transition: background-color 0.2s ease-in-out;
cursor: pointer;
}

button.links:enabled:hover {
Expand Down Expand Up @@ -125,6 +126,7 @@ button.links:enabled:hover {
margin: 0;
transition: background-color 0.2s ease-in-out;
background-color: #ddd;
cursor: pointer;
}

.check-version:hover {
Expand Down
2 changes: 2 additions & 0 deletions src/angular/src/app/pages/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class AboutComponent implements OnInit {
this._http.get<any>(this.github_release_url).subscribe(
data => {
this.last_version = data.name;
console.log(this.current_version, this.last_version)
console.log(this.current_version < this.last_version)
if (this.current_version < this.last_version) {
this.up_to_date = false;
this.html_url = data.html_url;
Expand Down
14 changes: 9 additions & 5 deletions src/angular/src/app/pages/account/account.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ <h2 class="title-cloud" (click)="openTab(session.domain)">
<div style="display: flex;flex-direction: row;">
<button class="cloud token tooltip left" (click)="openManageTokens(session.domain, 'user')">
<img class="icon"src="assets/list.svg">
<span class="tooltiptext">Manage</span>
<span class="tooltiptext">Manage Tokens</span>
</button>
<button class="cloud token tooltip right" (click)="openCreateToken(session.domain, 'user')">
<img class="icon" src="assets/add.svg">
<span class="tooltiptext">Create</span>
<span class="tooltiptext">Create Token</span>
</button>
</div>
</div>
Expand All @@ -39,21 +39,25 @@ <h2 class="title-cloud" (click)="openTab(session.domain)">
<div style="display: flex;flex-direction: row;">
<button class="cloud token tooltip left" (click)="openManageTokens(session.domain, 'org')">
<img class="icon"src="assets/list.svg">
<span class="tooltiptext">Manage</span>
<span class="tooltiptext">Manage Tokens</span>
</button>
<button class="cloud token tooltip right" (click)="openCreateToken(session.domain, 'org')">
<img class="icon" src="assets/add.svg">
<span class="tooltiptext">Create</span>
<span class="tooltiptext">Create Token</span>
</button>
</div>
</div>
</div>
</div>
</div>
<div *ngIf="sessions.length == 0" class="no-account">
<div *ngIf="sessions.length == 0 && is_working == false" class="notice-text">
<div>Sorry, I'm not able to find any Mist Session in this browser...</div>
<div>Please log in to your Mist Dashobard first.</div>
</div>
<div *ngIf="sessions.length == 0 && is_working == true" class="notice-text">
<div>I'm still eating your cookies... Not done yet...</div>
<div>Please wait a bit more... Thanks!</div>
</div>

<app-account-manage [ngClass]="{hidden: manageTokens == '' || scope !='user'}" class="popup white" [sessionEvent]="enventSession.asObservable()" (closeManageTokens)="closeManageTokens()" [enventManageTokens]="enventManageTokens.asObservable()"></app-account-manage>
<app-account-create [ngClass]="{hidden: createToken == '' || scope != 'user'}" class="popup transparent" [sessionEvent]="enventSession.asObservable()" (closeCreateToken)="closeCreateToken()" [enventCreateToken]="enventCreateToken.asObservable()"></app-account-create>
Expand Down
52 changes: 5 additions & 47 deletions src/angular/src/app/pages/account/account.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
flex-direction: column;
}

.no-account {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 1em;
text-align: center;
font-weight: 200;
height: 100%;
}

.popup {
position: absolute;
top: 50px;
Expand Down Expand Up @@ -83,6 +72,7 @@
display: flex;
flex-direction: row;
align-items: center;
cursor: pointer;
}

.title-cloud img {
Expand Down Expand Up @@ -145,43 +135,11 @@ button.token {
align-items: center;
justify-content: center;
padding: 0.1em;
cursor: pointer;
}

///////////////////////
// TOOTLTIP
.tooltip {
position: relative;
display: inline-block;
}

// tooltip
.tooltip .tooltiptext {
visibility: hidden;
width: 60px;
background-color: #00000061;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 4px 0;
position: absolute;
z-index: 1;
top: 150%;
left: 50%;
margin-left: -30px;
font-size: smaller;
}

.tooltip .tooltiptext::after {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #00000061 transparent;
}

.tooltip:hover .tooltiptext {
visibility: visible;
transition: visibility 0.2s ease-in-out, opacity 0.2s ease-in-out;
top: 130%;
left: 30%;
}
7 changes: 4 additions & 3 deletions src/angular/src/app/pages/account/account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export class AccountComponent implements OnInit {
".gc1.mist.com"
]

sessions: SessionElement[] = []

sessions: SessionElement[] = [];
is_working=true;

ngOnInit() {
//console.log(this.cookies)
this.is_working = true;
this.sessions = [];
chrome.cookies.getAll({}, (cookies) => {
cookies.forEach((cookie) => {
Expand Down Expand Up @@ -104,6 +104,7 @@ export class AccountComponent implements OnInit {
})
}
})
this.is_working = false;
}

processOrgs(privileges: any[]): OrgElement[] {
Expand Down
51 changes: 8 additions & 43 deletions src/angular/src/app/pages/api/api.component.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
<div class="content no-grow">
<h2>Page Info</h2>
<div *ngIf="!org_id" class="not_mist">
<div>Sorry, this website does not look like a Mist Organization...</div>
<div>If you think I'm wrong, please send me an email with the current URL.</div>
<app-api-manage *ngIf="display=='manage'"></app-api-manage>
<app-api-django *ngIf="display=='django'"></app-api-django>
<div *ngIf="display !='manage' && display!='django'" class="notice-text">
<div>
This page is not supported by the application yet...
</div>
<div *ngIf="org_id">
<div class="box-ids" *ngIf="org_id">
<label class="ids" for="org_id">ORG ID</label>
<div class=box-ids-input>
<input class="ids" type="text" readonly [(value)]="org_id" [ngClass]="focused == 'org_id'? 'focused' : ''" id="org_id" #org_id_input>
<button class="copy-ids" name="copy" (click)="copyId(org_id_input)">
<img class="copy-ids" src="assets/copy.svg" alt="copy">
</button>
</div>
</div>
<div class="box-ids" *ngIf="site_id">
<label class="ids" for="site_id">SITE ID</label>
<div class=box-ids-input>
<input class="ids" type="text" readonly [(value)]="site_id" [ngClass]="focused == 'site_id'? 'focused' : ''" id="site_id" #site_id_input>
<button class="copy-ids" name="copy" (click)="copyId(site_id_input)">
<img class="copy-ids" src="assets/copy.svg" alt="copy">
</button>
</div>
</div>
<div class="box-ids" *ngIf="obj_id">
<label class="ids" for="obj_id">{{obj_name | uppercase}} ID</label>
<div class=box-ids-input>
<input class="ids" type="text" readonly [(value)]="obj_id" [ngClass]="focused == 'obj_id'? 'focused': ''" id="obj_id" #obj_id_input>
<button class="copy-ids" name="copy" (click)="copyId(obj_id_input)">
<img class="copy-ids" src="assets/copy.svg" alt="copy">
</button>
</div>
</div>
</div>
</div>
<div *ngIf="quick_links.length > 0" class="content no-grow">
<h2>Quick API Access</h2>
<div class="box-apitab">
<button *ngFor="let quick_link of quick_links"  class="apitab" (click)="openApiTab(quick_link.url)">
<div>{{quick_link.name | uppercase}}</div>
<img class="icon-open" src="assets/open.svg" alt="open">
</button>

<div style="margin-top:1em;">If you think it should, please create a request to report your current URL.</div>
<div>
<button class="request" (click)="openTab()">Create a Request</button>
</div>
</div>
14 changes: 14 additions & 0 deletions src/angular/src/app/pages/api/api.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,18 @@ button.copy-ids:hover img.copy-ids {

img.copy-ids {
height: 20px;
}

button.request {
margin: 2em;
background-color: unset;
border: 1px solid lightgray;
border-radius: 5px;
cursor: pointer;
box-shadow: rgb(0 0 0 / 5%) 0px 0px 0px 1px;
transition: background-color 0.2s ease-in-out;
}

button.request:hover {
background-color: lightgray;
}
Loading

0 comments on commit cadd041

Please sign in to comment.