Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MB-47270 Upgrade the views page to angular
New components added: - Codemirror Editor. Change-Id: Ib886babc780f331052c095b6df86fbd1368f0b1b Reviewed-on: http://review.couchbase.org/c/ns_server/+/157224 Well-Formed: Build Bot <build@couchbase.com> Reviewed-by: Raluca Lupu <raluca.lupu@couchbase.com> Tested-by: Matthew <matthew.dawber@couchbase.com>
- Loading branch information
Matthew Dawber
committed
Oct 28, 2021
1 parent
3ab910f
commit f8051fe
Showing
58 changed files
with
2,764 additions
and
1,774 deletions.
There are no files selected for viewing
52 changes: 0 additions & 52 deletions
52
priv/public/ui/app/components/directives/mn_filter/mn_filter.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2021-Present Couchbase, Inc. | ||
Use of this software is governed by the Business Source License included in | ||
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
file, in accordance with the Business Source License, use of this software will | ||
be governed by the Apache License, Version 2.0, included in the file | ||
licenses/APL2.txt. | ||
*/ | ||
|
||
import { Component, ChangeDetectionStrategy, ViewChild } from '@angular/core'; | ||
import { MnLifeCycleHooksToStream } from './mn.core.js'; | ||
import { MnHelperService } from './mn.helper.service.js'; | ||
import '../libs/codemirror.javascript.js'; | ||
|
||
export { MnCodeMirrorEditorComponent }; | ||
|
||
class MnCodeMirrorEditorComponent extends MnLifeCycleHooksToStream { | ||
static get annotations() { return [ | ||
new Component({ | ||
selector: "mn-codemirror-editor", | ||
templateUrl: "app/mn.codemirror.editor.html", | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
queries: { | ||
editor: new ViewChild('editor') | ||
}, | ||
inputs: ['mnText', 'mnReadOnly', 'mnControl'] | ||
}) | ||
]} | ||
|
||
static get parameters() { return [ | ||
MnHelperService | ||
]} | ||
|
||
constructor(mnHelperService) { | ||
super(); | ||
|
||
this.mnHelperService = mnHelperService; | ||
} | ||
|
||
/* Instantiate an instance of codeMirror, default options passed in as a second argument. | ||
mnText input is set as the default text value. */ | ||
ngOnInit() { | ||
this.codeMirror = this.mnHelperService.createCodeMirror(this.editor.nativeElement, { | ||
lineNumbers: true, | ||
lineWrapping: true, | ||
matchBrackets: true, | ||
tabSize: 2, | ||
mode: { name: "javascript", json: true }, | ||
readOnly: this.mnReadOnly || false | ||
}); | ||
|
||
this.codeMirror.instance.setValue(this.mnText || ""); | ||
|
||
if (this.mnControl) { | ||
this.codeMirror.onChange.subscribe(val => { | ||
let text = this.getValue(val); | ||
this.mnControl.patchValue(text); | ||
}); | ||
} | ||
} | ||
|
||
/* Useful for setting the input if it changes from the parent component. */ | ||
ngOnChanges() { | ||
if (this.codeMirror) { | ||
this.codeMirror.instance.setValue(this.mnText); | ||
} | ||
} | ||
|
||
getValue(event) { | ||
return event[0].getValue(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- | ||
Copyright 2021-Present Couchbase, Inc. | ||
Use of this software is governed by the Business Source License included in | ||
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
file, in accordance with the Business Source License, use of this software will | ||
be governed by the Apache License, Version 2.0, included in the file | ||
licenses/APL2.txt. | ||
--> | ||
|
||
<textarea #editor></textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2021-Present Couchbase, Inc. | ||
Use of this software is governed by the Business Source License included in | ||
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
file, in accordance with the Business Source License, use of this software will | ||
be governed by the Apache License, Version 2.0, included in the file | ||
licenses/APL2.txt. | ||
*/ | ||
|
||
import { NgModule } from '@angular/core'; | ||
import { MnCodeMirrorEditorComponent } from './mn.codemirror.editor.component.js'; | ||
|
||
export { MnCodeMirrorEditorModule }; | ||
|
||
class MnCodeMirrorEditorModule { | ||
static get annotations() { return [ | ||
new NgModule({ | ||
declarations: [ | ||
MnCodeMirrorEditorComponent, | ||
], | ||
exports: [ | ||
MnCodeMirrorEditorComponent | ||
] | ||
}) | ||
]} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2021-Present Couchbase, Inc. | ||
Use of this software is governed by the Business Source License included in | ||
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
file, in accordance with the Business Source License, use of this software will | ||
be governed by the Apache License, Version 2.0, included in the file | ||
licenses/APL2.txt. | ||
*/ | ||
|
||
import { Injectable } from "/ui/web_modules/@angular/core.js"; | ||
import { HttpClient } from '/ui/web_modules/@angular/common/http.js'; | ||
import { UIRouter } from '/ui/web_modules/@uirouter/angular.js'; | ||
import { switchMap, shareReplay, pluck, withLatestFrom, | ||
combineLatest, distinctUntilChanged } from '../web_modules/rxjs/operators.js'; | ||
import { Subject, BehaviorSubject } from '../web_modules/rxjs.js'; | ||
|
||
export { MnDocumentsService } | ||
|
||
class MnDocumentsService { | ||
static get annotations() { return [ | ||
new Injectable() | ||
]} | ||
|
||
static get parameters() { return [ | ||
HttpClient, | ||
UIRouter | ||
]} | ||
|
||
constructor(http, uiRouter) { | ||
this.http = http; | ||
this.stream = {}; | ||
|
||
this.stream.recalculateRandomDocument = new BehaviorSubject(); | ||
this.stream.getManualDocument = new Subject(); | ||
|
||
this.commonBucket = uiRouter.globals.params$ | ||
.pipe(pluck('commonBucket'), | ||
distinctUntilChanged()); | ||
|
||
this.stream.getDocuments = new BehaviorSubject() | ||
.pipe(switchMap(this.getDocuments.bind(this)), | ||
shareReplay({refCount: true, bufferSize: 1})); | ||
|
||
this.stream.getDocument = this.stream.getManualDocument | ||
.pipe(switchMap(this.getDocument.bind(this)), | ||
shareReplay({refCount: true, bufferSize: 1})); | ||
|
||
this.stream.getRandomDocument = | ||
this.stream.recalculateRandomDocument | ||
.pipe(combineLatest(this.commonBucket), | ||
pluck(1), | ||
switchMap(this.getRandomKey.bind(this)), | ||
pluck('key'), | ||
withLatestFrom(this.commonBucket), | ||
switchMap(this.getDocument.bind(this)), | ||
shareReplay({ bufferSize: 1, refCount: true })); | ||
} | ||
|
||
getDocumentsURI(params) { | ||
let bucket = params.bucket || params.commonBucket; | ||
let base = "/pools/default/buckets/" + encodeURIComponent(bucket); | ||
|
||
return base + "/docs"; | ||
} | ||
|
||
buildDocumentUrl(params) { | ||
return this.getDocumentsURI(params) + '/' + encodeURIComponent(params.documentId); | ||
} | ||
|
||
getDocument([key, bucket]) { | ||
let params = { bucket, documentId: key} | ||
return this.http.get(this.buildDocumentUrl(params)); | ||
} | ||
|
||
getDocuments(params) { | ||
return this.http.get(this.getDocumentsURI(params)); | ||
} | ||
|
||
getRandomKey(bucket) { | ||
return this.http.get(`/pools/default/buckets/${encodeURIComponent(bucket)}/localRandomKey`); | ||
} | ||
} |
Oops, something went wrong.