Skip to content

Commit

Permalink
fixes for deployment modals and files
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Mar 26, 2024
1 parent 3d490bc commit fcfc9f5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/app/models/catalog.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export enum DeployMode {

export interface AdapterSettingModel {
subOf: string;
type: string;
name: string;
nameAlias: string;
alias: any;
Expand Down
6 changes: 4 additions & 2 deletions src/app/services/crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class CrudService {
private reconnected = new EventEmitter<boolean>();
private httpUrl = this._settings.getConnection('crud.rest');
private httpOptions = {headers: new HttpHeaders({'Content-Type': 'application/json'})};
private httpOptionsPart = {headers: new HttpHeaders({'Content-Type': 'multipart/form-data'})};
private socket;

// rendering routerLinks from string might not be possible:7
Expand Down Expand Up @@ -529,8 +530,9 @@ export class CrudService {
return this._http.get(`${this.httpUrl}/getAvailableSources`);
}

createAdapter(adapter: AdapterModel) {
return this._http.post(`${this.httpUrl}/createAdapter`, adapter, this.httpOptions);
createAdapter(adapter: AdapterModel, formdata: FormData) {
formdata.set("body", JSON.stringify(adapter))
return this._http.post(`${this.httpUrl}/createAdapter`, formdata);
}


Expand Down
27 changes: 11 additions & 16 deletions src/app/views/adapters/adapters.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h4 cModalTitle>{{ activeMode() ? "Settings" : "Deployment Mode" }}</h4>
<div class="form-group" *ngFor="let control of editingAdapterForm.controls | keyvalue">
<ng-container *ngIf="getAdapterSetting(control.key)">
<c-input-group
*ngIf="!getAdapterSetting(control.key).template.options && !getAdapterSetting(control.key).template.fileNames">
*ngIf="!getAdapterSetting(control.key).template.options && getAdapterSetting(control.key).template.type.toLowerCase() !== 'directory'">
<span cInputGroupText cTooltipPlacement="left"
[cTooltip]="getAdapterSetting(control.key).template.description">
{{ control.key }}
Expand Down Expand Up @@ -175,7 +175,9 @@ <h4 cModalTitle>{{ activeMode() ? "Settings" : "Deployment Mode" }}</h4>
</c-input-group>
</ng-template>
</div>
<c-input-group *ngIf="getAdapterSetting(control.key).template.fileNames">
<c-input-group
*ngIf="getAdapterSetting(control.key).template.type.toLowerCase() === 'directory'">
test
<span cInputGroupText cTooltipPlacement="left"
[cTooltip]="getAdapterSetting(control.key).template.description">{{ control.key }}</span>
<span cFormText *ngIf="!getAdapterSetting(control.key).template.modifiable" disabled></span>
Expand All @@ -185,7 +187,7 @@ <h4 cModalTitle>{{ activeMode() ? "Settings" : "Deployment Mode" }}</h4>
</span>
<input cFormControl type="file" multiple style="display: none" [id]="control.key"
[ngClass]="validate(editingAdapterForm, control.key)"
(change)="onFileChange($event, editingAdapterForm, control.key)">
(change)="onFileChange($event, control.key)">
<c-form-feedback>required</c-form-feedback>
</c-input-group>
</ng-container>
Expand Down Expand Up @@ -218,7 +220,7 @@ <h4 cModalTitle>{{ activeMode() ? "Settings" : "Deployment Mode" }}</h4>
*ngFor="let control of editingAvailableAdapterForm.controls | keyvalue: positionOrder()">
<ng-container *ngIf=" control.key !== 'uniqueName' && isSettingDisplayed(control.key)">
<c-input-group class="has-validation"
*ngIf="!getAdapterSetting(control.key).template.options && !getAdapterSetting(control.key).template.fileNames">
*ngIf="!getAdapterSetting(control.key).template.options && getAdapterSetting(control.key).template.type.toLowerCase() !== 'directory'">
<span cInputGroupText
[cTooltip]="getAdapterSetting(control.key).template.description"
cTooltipPlacement="left">{{ control.key }}</span>
Expand Down Expand Up @@ -262,21 +264,14 @@ <h4 cModalTitle>{{ activeMode() ? "Settings" : "Deployment Mode" }}</h4>
[value]="option">{{ getAdapterSetting(control.key).template.alias[option] }}
</option>
</select>
<c-form-feedback>{{ getGenericFeedback((control.key)) }}</c-form-feedback>
<c-form-feedback>{{ getGenericFeedback(control.key) }}</c-form-feedback>
</c-input-group>
</ng-template>
</ng-container>
<c-input-group *ngIf="getAdapterSetting(control.key).template.fileNames">
<span cInputGroupText cTooltipPlacement="left"
[cTooltip]="getAdapterSetting(control.key).template.description"
[cTooltipVisible]="!!getAdapterSetting(control.key).template.description">{{ control.key }}</span>
<span cFormText
style="position: relative; text-align: left; white-space: nowrap; overflow: hidden"></span>
<input type="file" multiple style="display: none" [id]="control.key"
[ngClass]="validate(control.value, control.key)"
(change)="onFileChange($event, editingAvailableAdapterForm, control.key)">
{{ fileLabel }}

<c-input-group
*ngIf="getAdapterSetting(control.key).template.type.toLowerCase() === 'directory'">
<label cInputGroupText>{{ control.key }}</label>
<input cFormControl type="file" (change)="onFileChange($event, control.key)"/>
<c-form-feedback>{{ getGenericFeedback(control.key) }}</c-form-feedback>
</c-input-group>
</ng-container>
Expand Down
72 changes: 37 additions & 35 deletions src/app/views/adapters/adapters.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {ToasterService} from '../../components/toast-exposer/toaster.service';
import {
AbstractControl,
FormGroup,
UntypedFormArray,
UntypedFormBuilder,
UntypedFormControl,
UntypedFormGroup,
Expand Down Expand Up @@ -106,6 +105,8 @@ export class AdaptersComponent implements OnInit, OnDestroy {

protected readonly Task = Task;

private readonly files = new Map<string, File>();


readonly positionOrder = () => {
return (a, b) => {
Expand Down Expand Up @@ -141,13 +142,14 @@ export class AdaptersComponent implements OnInit, OnDestroy {
}
const fc = {};


for (const setting of adapter.settings.values()) {
const validators = [];
if (setting.template.required) {
validators.push(Validators.required);
}
let val = setting.template.defaultValue;
if (setting.template.fileNames) {
if (setting.template.type.toLowerCase() === 'directory') {
fc[setting.template.name] = this._fb.array([]);
} else {
if (setting.template.options) {
Expand Down Expand Up @@ -265,6 +267,7 @@ export class AdaptersComponent implements OnInit, OnDestroy {

async initDeployModal(adapter: AdapterTemplateModel) {
this.activeMode.set(null);

// if we only have one mode we directly set it
if (adapter.modes.length === 0) {
this.activeMode.set(DeployMode.ALL);
Expand All @@ -277,22 +280,21 @@ export class AdaptersComponent implements OnInit, OnDestroy {
this.modalActive = true;
}

onFileChange(event, form: UntypedFormGroup, key) {
onFileChange(event, key) {

const files = event.target.files;
if (files) {
const fileNames = [];
const arr = form.controls[key] as UntypedFormArray;
arr.clear();
for (let i = 0; i < files.length; i++) {
fileNames.push(files.item(i)._name);
arr.push(this._fb.control(files.item(i)));
}
this.fileLabel = fileNames.join(', ');
} else {
const arr = form.controls[key] as UntypedFormArray;
arr.clear();
this.fileLabel = 'Choose File';
if (!files) {
return;
}
const fileNames = [];
const setting = this.getAdapterSetting(key);
setting.template.fileNames = [];
for (let file of files) {
fileNames.push(file.name);
this.files.set(file.name, file);
setting.template.fileNames.push(file.name)
}

}

getFeedback(form: UntypedFormGroup) {
Expand Down Expand Up @@ -355,22 +357,19 @@ export class AdaptersComponent implements OnInit, OnDestroy {
setting.current = new AdapterSettingValueModel(k, null);
}

if (setting.template.fileNames) {
if (setting.template.type.toLowerCase() === "directory") {
const fileNames = [];
const arr = v as UntypedFormArray;
for (let i = 0; i < arr.length; i++) {
const file = arr.at(i).value as File;
fd.append(file.name, file);
fileNames.push(file.name);

for (let fileName of setting.template.fileNames) {
fd.append(fileName, this.files.get(fileName));
}
setting.current.value = fileNames.toString();
setting.current.value = JSON.stringify(setting.template.fileNames);
} else {
setting.current.value = v.value;
}

deploy.settings.set(k, setting.current);
}
console.log(deploy);

if (deploy.settings.hasOwnProperty('method') && deploy.settings['method'].defaultValue === 'link') {
// secure deploy
Expand All @@ -383,21 +382,21 @@ export class AdaptersComponent implements OnInit, OnDestroy {
this.data = {data: fd, deploy: deploy};
if (!id || id.trim() === '') {
// file is already placed
this.continueSecureDeploy();
this.continueSecureDeploy(fd);
}
}
);

} else {
// normal deploy
this.startDeploying(deploy);
this.startDeploying(deploy, fd);
}

}

continueSecureDeploy() {
continueSecureDeploy(formdata: FormData = new FormData()) {
this.handshaking = false;
this.startDeploying(this.data.deploy);
this.startDeploying(this.data.deploy, formdata);
}

createSecureFile() {
Expand All @@ -414,10 +413,10 @@ export class AdaptersComponent implements OnInit, OnDestroy {
}, 0);
}

private startDeploying(deploy: AdapterModel) {

private startDeploying(deploy: AdapterModel, formdata: FormData) {
console.log(deploy)
this.deploying = true;
this._crud.createAdapter(deploy).subscribe({
this._crud.createAdapter(deploy, formdata).subscribe({
next: (result: RelationalResult) => {
if (!result.error) {
this._toast.success('Deployed "' + deploy.name + '"', result.query);
Expand Down Expand Up @@ -559,11 +558,14 @@ export class AdaptersComponent implements OnInit, OnDestroy {

const setting = this.getAdapterSetting(keys[0]);

this.subgroups.set(keys[0], setting[1].value);
if (setting && setting.template) {
this.subgroups.set(keys[0], setting.template.defaultValue);
} else {
return false;
}

}


return this.subgroups.has(keys[0]) && this.subgroups.get(keys[0]) === keys[1];
}

Expand Down Expand Up @@ -598,6 +600,7 @@ export class AdaptersComponent implements OnInit, OnDestroy {
}
return true;
}

}

// see https://angular.io/guide/form-validation#custom-validators
Expand All @@ -623,6 +626,7 @@ class Adapter {
mode: DeployMode;
task: Task;
type: AdapterType;
settings: Map<string, MergedSetting>;

constructor(uniqueName: string, adapterName: string, persistent: boolean, modes: DeployMode[], type: AdapterType, settings: Map<string, MergedSetting>, task: Task) {
this.uniqueName = uniqueName;
Expand All @@ -635,8 +639,6 @@ class Adapter {
}


settings: Map<string, MergedSetting>;

public static from(adapter: AdapterTemplateModel, current: AdapterModel | null, task: Task): Adapter {
const settings: Map<string, MergedSetting> = new Map();

Expand Down

0 comments on commit fcfc9f5

Please sign in to comment.