Skip to content

Commit

Permalink
Merge branch 'master' into update-angular-dependencies-to-17
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrosx authored Sep 19, 2024
2 parents d0fa544 + 7d2a872 commit a61541e
Show file tree
Hide file tree
Showing 75 changed files with 3,240 additions and 1,110 deletions.
373 changes: 246 additions & 127 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
<mat-icon>search</mat-icon>
Search
</button>
<button
mat-raised-button
<button
mat-raised-button
color="primary"
class="full-text-clear-button"
data-cy="search-clear-button"
data-cy="search-clear-button"
(click)="onClear()"
>
<mat-icon>clear</mat-icon>
Clear Text
<mat-icon>undo</mat-icon>
Reset Search
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class FullTextSearchBarComponent implements OnInit, OnDestroy {
onClear(): void {
this.searchTerm = "";
this.searchTermSubject.next(undefined);
//this.searchClickSubject.next();
this.searchClickSubject.next();
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { ActionDataset } from "./datafiles-action.interfaces";
describe("1000: DatafilesActionComponent", () => {
let component: DatafilesActionComponent;
let fixture: ComponentFixture<DatafilesActionComponent>;
let htmlForm: HTMLFormElement;
let htmlInput: HTMLInputElement;

const actionsConfig = [
{
Expand Down Expand Up @@ -129,14 +131,20 @@ describe("1000: DatafilesActionComponent", () => {
id: "4ac45f3e-4d79-11ef-856c-6339dab93bee",
});

const browserWindowMock = {
document: {
write() {},
body: {
setAttribute() {},
},
},
} as unknown as Window;
// const browserWindowMock = {
// document: {
// write() {},
// body: {
// setAttribute() {},
// },
// },
// } as unknown as Window;

beforeAll(() => {
htmlForm = document.createElement("form");
(htmlForm as HTMLFormElement).submit = () => {};
htmlInput = document.createElement("input");
});

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -494,9 +502,22 @@ describe("1000: DatafilesActionComponent", () => {
});
});

function getFakeElement(elementType: string): HTMLElement {
const element = new MockHtmlElement(elementType);
return element as unknown as HTMLElement;
function createFakeElement(elementType: string): HTMLElement {
//const element = new MockHtmlElement(elementType);
//return element as unknown as HTMLElement;
let element: HTMLElement = null;

switch (elementType) {
case "form":
element = htmlForm.cloneNode(true) as HTMLElement;
break;
case "input":
element = htmlInput.cloneNode(true) as HTMLElement;
break;
default:
element = null;
}
return element;
}

it("0400: Form submission should have all files when Download All is clicked", async () => {
Expand All @@ -505,8 +526,9 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFilesType.none,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);

spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

Expand All @@ -526,13 +548,13 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFilesType.none,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);
spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

expect(component.form.action).toEqual(
actionsConfig[actionSelectorType.download_all].url,
expect(component.form.action.replace(/\/$/, "")).toEqual(
actionsConfig[actionSelectorType.download_all].url.replace(/\/$/, ""),
);
});

Expand All @@ -542,8 +564,8 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFilesType.none,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);
spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

Expand All @@ -566,8 +588,8 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFile,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);
spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

Expand All @@ -592,8 +614,8 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFilesType.none,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);
spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

Expand All @@ -613,13 +635,13 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFilesType.none,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);
spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

expect(component.form.action).toEqual(
actionsConfig[actionSelectorType.notebook_all].url,
expect(component.form.action.replace(/\/$/, "")).toEqual(
actionsConfig[actionSelectorType.notebook_all].url.replace(/\/$/, ""),
);
});

Expand All @@ -630,8 +652,8 @@ describe("1000: DatafilesActionComponent", () => {
maxSizeType.higher,
selectedFile,
);
spyOn(document, "createElement").and.callFake(getFakeElement);
spyOn(window, "open").and.returnValue(browserWindowMock);
spyOn(document, "createElement").and.callFake(createFakeElement);
//spyOn(window, "open").and.returnValue(browserWindowMock);

component.perform_action();

Expand Down
52 changes: 41 additions & 11 deletions src/app/datasets/datafiles-actions/datafiles-action.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ export class DatafilesActionComponent implements OnInit, OnChanges {
visible = true;
use_mat_icon = false;
use_icon = false;
//disabled = false;
disabled_condition = "false";
selectedTotalFileSize = 0;
numberOfFileSelected = 0;

form: HTMLFormElement;
form: HTMLFormElement = null;

constructor(private userApi: UserApi) {
this.userApi.jwt().subscribe((jwt) => {
Expand Down Expand Up @@ -92,10 +91,6 @@ export class DatafilesActionComponent implements OnInit, OnChanges {
).length;
}

// compute_disabled() {
// this.disabled = eval(this.disabled_condition);
// }

get disabled() {
this.update_status();
this.prepare_disabled_condition();
Expand All @@ -111,10 +106,24 @@ export class DatafilesActionComponent implements OnInit, OnChanges {
}

perform_action() {
const action_type = this.actionConfig.type || "form";
switch (action_type) {
case "form":
default:
return this.type_form();
}
}

type_form() {
if (this.form !== null) {
document.body.removeChild(this.form);
}

this.form = document.createElement("form");
this.form.target = this.actionConfig.target;
this.form.method = this.actionConfig.method;
this.form.target = this.actionConfig.target || "_self";
this.form.method = this.actionConfig.method || "POST";
this.form.action = this.actionConfig.url;
this.form.style.display = "none";

this.form.appendChild(
this.add_input("auth_token", this.userApi.getCurrentToken().id),
Expand All @@ -128,19 +137,40 @@ export class DatafilesActionComponent implements OnInit, OnChanges {
this.add_input("directory", this.actionDataset.sourceFolder),
);

for (const [index, item] of this.files.entries()) {
let index = 0;
for (const item of this.files) {
if (
this.actionConfig.files === "all" ||
(this.actionConfig.files === "selected" && item.selected)
) {
this.form.appendChild(
this.add_input("files[" + index + "]", item.path),
);
index = index + 1;
}
}

//document.body.appendChild(form);
document.body.appendChild(this.form);
this.form.submit();
window.open("", "view");

return true;
}

/*
* future development
*
type_fetch() {
const data = new URLSearchParams();
for (const pair of new FormData(formElement)) {
data.append(pair[0], pair[1]);
}
fetch(url, {
method: 'post',
body: data,
})
.then(…);
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ActionConfig {
files: string;
mat_icon?: string;
icon?: string;
type?: string;
url: string;
target: string;
authorization: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from "@angular/core";
import { Component, Input } from "@angular/core";
import { ActionConfig, ActionDataset } from "./datafiles-action.interfaces";
import { DataFiles_File } from "datasets/datafiles/datafiles.interfaces";
import { AppConfigService } from "app-config.service";
Expand Down
Loading

0 comments on commit a61541e

Please sign in to comment.