Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Review support cube builder custom identity name (close #119) #120

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changes


## Version 0.6.1 (2022-10-04)

- Add support to customize data cube name of IDT/Temporal Composed [`#119`](https://github.com/brazil-data-cube/dc-manager/issues/119)


## Version 0.6.0 (2022-09-26)

- Change LICENSE to GPLv3
Expand Down
2 changes: 1 addition & 1 deletion data-cube-manager/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion data-cube-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-cube-manager",
"version": "0.6.0",
"version": "0.6.1",
"license": "GPLv3",
"scripts": {
"ng": "ng",
Expand Down
2 changes: 1 addition & 1 deletion data-cube-manager/src/app/admin/admin-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class AdminGuardService implements CanActivateChild {
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | boolean {
const token = localStorage.getItem('DC_MANAGER_api_token')
return token ? true : false;
return !!token || token === "";
}
}
1 change: 1 addition & 0 deletions data-cube-manager/src/app/admin/admin.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const initialState: AdminState = {
definitionInfos: {
bucket: '',
name: '',
identity: '',
version: null,
public: true,
resolution: null,
Expand Down
1 change: 1 addition & 0 deletions data-cube-manager/src/app/admin/admin.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface IBand {
export interface DefinitionCube {
bucket: string;
name: string;
identity: string;
version: number;
public: boolean;
resolution: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SceneDetailsComponent } from './scene-details/scene-details.component';
import * as moment from 'moment';
import { ReprocessDialogComponent } from 'app/admin/components/reprocess-dialog/reprocess-dialog.component';
import { DomSanitizer } from '@angular/platform-browser';
import { isIdentity } from 'app/shared/helpers/cube';


@Component({
Expand Down Expand Up @@ -325,7 +326,7 @@ export class CheckCubeComponent implements OnInit {
}

isIdentity() {
return this.cube && this.cube.name.split('_').length === 2;
return isIdentity(this.cube);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,17 @@ <h3 style="display: flex; align-items: center;">
</button>
</div>

<div class="col-lg-6 col-md-6 col-sm-12">
<div class="col-lg-4 col-md-4 col-sm-12">
<mat-form-field appearance="outline">
<mat-label>Cube Name</mat-label>
<input matInput placeholder="Cube Name" formControlName="name">
<span matSuffix>
<span style="color: green">Full Name: </span>
<b>{{ getCubeFullName() }}<span *ngIf="formCreateCube.get('temporalComposite').value !== 'Anull'"
style="color: red">_FUNC</span></b>
</span>
<mat-error>
<form-field-error [errors]="formCreateCube.get('name').errors"></form-field-error>
</mat-error>
</mat-form-field>
</div>

<div class="col-lg-3 col-md-3 col-sm-12">
<div class="col-lg-2 col-md-2 col-sm-12">
<mat-form-field appearance="outline">
<mat-label>Version</mat-label>
<input matInput type="number" min="1" placeholder="Version" formControlName="version">
Expand All @@ -50,7 +45,7 @@ <h3 style="display: flex; align-items: center;">
</mat-form-field>
</div>

<div class="col-lg-3 col-md-3 col-sm-12">
<div class="col-lg-2 col-md-2 col-sm-12">
<mat-form-field appearance="outline">
<mat-label>Resolution</mat-label>
<input matInput type="number" min="1" placeholder="Resolution" formControlName="resolution">
Expand All @@ -60,6 +55,16 @@ <h3 style="display: flex; align-items: center;">
</mat-form-field>
</div>

<div class="col-lg-4 col-md-4 col-sm-12">
<mat-form-field appearance="outline" *ngIf="supportsIdentityField()">
<mat-label>Identity Cube Name</mat-label>
<input matInput placeholder="Identity Cube Name" formControlName="identity">
<mat-error>
<form-field-error [errors]="formCreateCube.get('identity').errors"></form-field-error>
</mat-error>
</mat-form-field>
</div>

<div class="col-lg-6 col-md-6 col-sm-12 box_input_with_button">
<mat-form-field appearance="outline">
<mat-label>Temporal Composition</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FormGroup, FormBuilder, Validators } from '@angular/forms'
import { setDefinition } from 'app/admin/admin.action'
import { BucketsModal } from './buckets/buckets.component'
import { CustomBandDialogComponent } from './custom-band-dialog/custom-band-dialog.component'
import { getCubeBuilderVersion } from 'app/shared/helpers/cube'

@Component({
selector: 'app-create-cube-definition',
Expand Down Expand Up @@ -49,7 +50,11 @@ export class CreateCubeDefinitionComponent implements OnInit {
public dialog: MatDialog) {
this.formCreateCube = this.fb.group({
bucket: ['', this.environmentVersion === 'cloud' ? [Validators.required] : []],
name: ['', [Validators.required, Validators.pattern('^[a-zA-Z0-9-]*$')]],
name: ['', [Validators.required, Validators.pattern('^[a-zA-Z0-9-_]*$')]],
identity: ['', this.supportsIdentityField() ?
[Validators.required, Validators.pattern('^[a-zA-Z0-9-_]*$')] :
[]
],
version: ['', [Validators.required]],
resolution: ['', [Validators.required]],
temporalComposite: [{value: '', disabled: true}, [Validators.required]],
Expand Down Expand Up @@ -235,8 +240,7 @@ export class CreateCubeDefinitionComponent implements OnInit {
indexes.push(bandIndex);
}
}

this.store.dispatch(setDefinition({
const data = {
definition: {
bucket: this.formCreateCube.get('bucket').value,
name: this.formCreateCube.get('name').value,
Expand All @@ -252,25 +256,26 @@ export class CreateCubeDefinitionComponent implements OnInit {
qualityNodata: this.formCreateCube.get('qualityNodata').value,
public: this.formCreateCube.get('public').value
}
}))
}
if (this.supportsIdentityField()) {
data.definition['identity'] = this.formCreateCube.get('identity').value;
}

this.store.dispatch(setDefinition(data))
this.definitonCompleted = true
}
}

getCubeFullName() {
const name = this.formCreateCube.get('name').value
const resolution = this.formCreateCube.get('resolution').value
if (this.formCreateCube.get('temporalComposite').value.length) {
const temporalComposite = JSON.parse(this.formCreateCube.get('temporalComposite').value)
const unit = temporalComposite['unit'].replace('day', 'D').replace('month', 'M').replace('year', 'Y')
if (unit === 'null') {
return `${name}_${resolution}`
} else {
return `${name}_${resolution}_${temporalComposite['step']}${unit}`
if (unit !== 'null') {
return `${name}-${temporalComposite['step']}${unit}`
}
} else {
return `${name}_${resolution}`
}
return name;
}

getSelectedIndexes() {
Expand Down Expand Up @@ -373,4 +378,16 @@ export class CreateCubeDefinitionComponent implements OnInit {
}
}
}

supportsIdentityField(): boolean {
const builderVersion = getCubeBuilderVersion();
if (!builderVersion || this.environmentVersion === 'cloud')
return false;

let [major, minor, patch] = builderVersion.split(".").map(value => Number.parseInt(value));

// Supported only >= 0.8.3
return (major == 0 && minor >= 8 && patch >= 3) ||
(major >= 1 && minor >= 0 && patch >= 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,7 @@ export class CreateCubePreviewComponent implements OnInit {
}

getCubeName(func) {
let cubeName = this.definition.name
let complement = '';

if (func !== 'IDT') {
complement = `_${this.getComplementCubeName(this.definition.temporal)}`;

if (this.environmentVersion === 'cloud') {
complement = `-${complement.split('_')[2]}`
}
}

return `${cubeName}${complement}`
return this.definition.name
}

getComplementCubeName(temporalSchema) {
Expand Down Expand Up @@ -199,6 +188,10 @@ export class CreateCubePreviewComponent implements OnInit {
parameters: parameters
}

if (this.definition.identity !== '') {
cube['datacube_identity'] = this.definition.identity
}

if (this.environmentVersion === 'cloud')
cube['bucket'] = this.definition.bucket

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h4 class="card-title">{{ cube.title }}</h4>
</tr>
<tr style="border-bottom: 1px dotted #CCC; padding: 10px">
<td class="text-success">Composite Function:</td>
<td>{{ cube.composite_function }}</td>
<td>{{ getCompositeFunction() }}</td>
</tr>
<tr style="border-bottom: 1px dotted #CCC; padding: 10px">
<td class="text-success">Temporal Composition:</td>
Expand Down Expand Up @@ -75,7 +75,7 @@ <h4 class="card-title">{{ cube.title }}</h4>
</div>

<div class="btns-check" *ngIf="cubeStatus">
<button *ngIf="(cubeStatus.finished || !cubeStarted()) && cube.composite_function.toUpperCase() !== 'IDENTITY'" mat-raised-button color="success" (click)="openModalUpdateCube()">
<button *ngIf="(cubeStatus.finished || !cubeStarted()) && getCompositeFunction() !== 'IDT'" mat-raised-button color="success" (click)="openModalUpdateCube()">
PROCESS CUBE
</button>
<a mat-raised-button *ngIf="countTiles > 0" color="primary" [routerLink]="['/check-cube', getCubeFullName(cube)]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ReprocessDialogComponent } from 'app/admin/components/reprocess-dialog/
import { UpdateCubeDialog } from 'app/admin/components/update-cube-dialog/update-cube-dialog.component';
import { DomSanitizer } from '@angular/platform-browser';
import { UpdateBandDialogComponent } from 'app/admin/components/update-band-dialog/update-band-dialog.component';
import { getCompositeFunction } from 'app/shared/helpers/cube';

@Component({
selector: 'app-details-cube',
Expand Down Expand Up @@ -248,6 +249,10 @@ export class DetailsCubeComponent implements OnInit {
(this.cubeStatus.not_done > 0 || this.cubeStatus.done > 0 || this.cubeStatus.error > 0);
}

public getCompositeFunction() {
return getCompositeFunction(this.cube);
}

/**
* event used when change Map
*/
Expand Down
8 changes: 6 additions & 2 deletions data-cube-manager/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ export class AppComponent implements OnInit {
this.spinner.hide()
}

if (res.token) {
if (this.validToken(res.token)) {
this.token = res.token
}
});
}

ngOnInit() {
if (!this.token) {
if (!this.validToken(this.token)) {
this.openTokenModal()
}
}

private validToken(token) {
return token || token === "";
}

openTokenModal() {
const dialogRef = this.dialog.open(TokenModal, {
width: '450px',
Expand Down
36 changes: 36 additions & 0 deletions data-cube-manager/src/app/shared/helpers/cube.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Helper to check if the given value is a string.
*/
export function isString(value: any): boolean {
return typeof value === 'string' || value instanceof String;
}


export function isIdentity(cube: any): boolean {
if (!cube) {
return false;
}
return getCompositeFunction(cube) === 'IDT';
}


export function getCompositeFunction(cube: any): string {
if (!cube) {
return ;
}
// For compatibility
let alias = cube.composite_function;
if (!isString(cube.composite_function)) {
alias = cube.composite_function.alias
}
return alias;
}


export function getCubeBuilderVersion(): string {
return localStorage.getItem("DC_MANAGER_BUILDER_VERSION");
}

export function setCubeBuilderVersion(version: string) {
localStorage.setItem("DC_MANAGER_BUILDER_VERSION", version);
}
7 changes: 5 additions & 2 deletions data-cube-manager/src/app/shared/token/token.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CubeBuilderService } from "app/services/cube-builder";
import { Store } from "@ngrx/store";
import { token, showLoading, closeLoading, setURLCubeBuilder } from "app/app.action";
import { MatSnackBar } from "@angular/material/snack-bar";
import { setCubeBuilderVersion } from "../helpers/cube";

@Component({
selector: 'token-modal',
Expand All @@ -24,9 +25,11 @@ export class TokenModal {
async verify() {
try {
this.store.dispatch(showLoading())
const _ = await this.cbs.verifyToken(this.urlService, this.token)
const resp = await this.cbs.verifyToken(this.urlService, this.token)
this.store.dispatch(token({ token: this.token }))
this.store.dispatch(setURLCubeBuilder({ url: this.urlService }))

setCubeBuilderVersion(resp.version);
window.location.reload();
this.dialogRef.close()

Expand All @@ -36,7 +39,7 @@ export class TokenModal {
verticalPosition: 'top',
panelClass: 'app_snack-bar-error'
});

} finally {
this.store.dispatch(closeLoading())
}
Expand Down