Skip to content

Commit

Permalink
chore(Authoring): Convert project asset authoring to Angular (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan authored Jul 24, 2023
1 parent e784b2a commit 4f58aad
Show file tree
Hide file tree
Showing 31 changed files with 925 additions and 129 deletions.
36 changes: 36 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"mathjax": "^3.2.2",
"ng-file-upload": "^12.2.13",
"ng-recaptcha": "^11.0.0",
"ng2-file-upload": "^4.0.0",
"ngx-filesize": "^3.0.2",
"rxjs": "^7.5.6",
"sockjs-client": "^1.6.0",
"svg.draggable.js": "2.2.0",
Expand Down Expand Up @@ -112,10 +114,10 @@
"karma-coverage": "^2.2.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "^5.0.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-json-fixtures-preprocessor": "0.0.6",
"karma-spec-reporter": "0.0.36",
"karma-webpack": "^5.0.0",
"karma-jasmine-html-reporter": "^2.0.0",
"prettier": "2.2.1",
"protractor": "~7.0.0",
"sass": "^1.50.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app/teacher/authoring-tool.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { NotebookAuthoringComponent } from '../../assets/wise5/authoringTool/not
import { StructureAuthoringModule } from '../../assets/wise5/authoringTool/structure/structure-authoring.module';
import { MilestonesAuthoringComponent } from '../../assets/wise5/authoringTool/milestones-authoring/milestones-authoring.component';
import { ChooseComponentLocationComponent } from '../../assets/wise5/authoringTool/node/chooseComponentLocation/choose-component-location.component';
import { ProjectAssetAuthoringModule } from '../../assets/wise5/authoringTool/project-asset-authoring/project-asset-authoring.module';

@NgModule({
declarations: [
Expand Down Expand Up @@ -61,6 +62,7 @@ import { ChooseComponentLocationComponent } from '../../assets/wise5/authoringTo
ImportComponentModule,
NodeAdvancedAuthoringModule,
PreviewComponentModule,
ProjectAssetAuthoringModule,
RouterModule,
StructureAuthoringModule,
WiseTinymceEditorModule
Expand Down
2 changes: 1 addition & 1 deletion src/assets/tinymce/wise/skin.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}
.tox-tinymce-aux {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
z-index: 1300;
z-index: 900;
}
.tox-tinymce *:focus,
.tox-tinymce-aux *:focus {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/tinymce/wise/skin.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/assets/tinymce/wise/skin.min.css.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { ConfigService } from '../../services/configService';
import { TeacherProjectService } from '../../services/teacherProjectService';
import * as angular from 'angular';
import { ProjectAssetService } from '../../../../app/services/projectAssetService';
import { NotificationService } from '../../services/notificationService';
import { Component } from '@angular/core';
import { UpgradeModule } from '@angular/upgrade/static';
import { isValidJSONString } from '../../common/string/string';
import { MatDialog } from '@angular/material/dialog';
import { AssetChooser } from '../project-asset-authoring/asset-chooser';
import { filter } from 'rxjs/operators';

@Component({
selector: 'advanced-project-authoring',
Expand All @@ -20,10 +22,10 @@ export class AdvancedProjectAuthoringComponent {
rubricDisplayed: boolean;

constructor(
private dialog: MatDialog,
private upgrade: UpgradeModule,
private configService: ConfigService,
private notificationService: NotificationService,
private projectAssetService: ProjectAssetService,
private projectService: TeacherProjectService
) {
this.projectId = this.configService.getProjectId();
Expand Down Expand Up @@ -88,14 +90,13 @@ export class AdvancedProjectAuthoringComponent {
}

chooseProjectScriptFile() {
const params = {
isPopup: true,
projectId: this.projectId,
target: 'scriptFilename'
};
this.projectAssetService.openAssetChooser(params).then((data: any) => {
this.assetSelected(data);
});
new AssetChooser(this.dialog, null, null, this.projectId)
.open('scriptFilename')
.afterClosed()
.pipe(filter((data) => data != null))
.subscribe((data: any) => {
this.assetSelected(data);
});
}

assetSelected({ assetItem }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,6 @@ export abstract class AbstractComponentAuthoring {
});
}

chooseAsset(target: string): void {
const params = {
isPopup: true,
nodeId: this.nodeId,
componentId: this.componentId,
target: target
};
this.openAssetChooser(params);
}

openAssetChooser(params: any): any {
return this.projectAssetService.openAssetChooser(params).then((data: any) => {
return this.assetSelected(data);
});
}

assetSelected({ nodeId, componentId, assetItem, target }): void {}

getComponents(nodeId: string): any[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface AssetChooserDialogData {
componentId: string;
isPopup: boolean;
nodeId: string;
projectId: number;
target: string;
targetObject: any;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ProjectAssetAuthoringComponent } from './project-asset-authoring.component';

export class AssetChooser {
constructor(
private dialog: MatDialog,
private nodeId: string,
private componentId: string,
private projectId: number = null
) {}

open(target: string, targetObject: any = null): MatDialogRef<ProjectAssetAuthoringComponent> {
return this.dialog.open(ProjectAssetAuthoringComponent, {
data: {
componentId: this.componentId,
isPopup: true,
nodeId: this.nodeId,
projectId: this.projectId,
target: target,
targetObject: targetObject
},
width: '80%'
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<div class="root">
<div
class="drop-box"
ng2FileDrop
(onFileDrop)="fileChosen($event)"
accept="image/*,application/pdf,text/csv,text/javascript"
i18n
>
Drop image or file here or click to upload!
<input
type="file"
accept="image/*,application/pdf,text/csv,text/javascript"
class="file-input"
(onFileSelected)="fileChosen($event)"
ng2FileSelect
multiple
/>
</div>
<div class="storage-usage-message">
<span i18n>
You are using {{ totalFileSize | filesize }} out of
{{ projectAssetTotalSizeMax | filesize }} ({{ projectAssetUsagePercentage.toFixed(0) }}%)
</span>
<span *ngIf="totalUnusedFilesSize != null && totalUnusedFilesSize !== 0" class="red"
>(Unused Files {{ totalUnusedFilesSize | filesize }} ({{
unusedFilesPercentage.toFixed(0)
}}%))
</span>
</div>
<div class="background-green">
{{ uploadSuccessMessage }}
<div *ngFor="let successFile of successFiles">
<b>{{ successFile.filename }}</b>
</div>
</div>
<div class="background-pink">
{{ uploadErrorMessage }}
<div *ngFor="let errorFile of errorFiles">
<b>{{ errorFile.filename }}</b> {{ errorFile.message }}
</div>
</div>
<mat-form-field>
<mat-label i18n>Sort Assets</mat-label>
<mat-select [(ngModel)]="assetSortBy" (ngModelChange)="assetSortByChanged()">
<mat-option value="aToZ" i18n>File Name A->Z</mat-option>
<mat-option value="zToA" i18n>File Name Z->A</mat-option>
<mat-option value="smallToLarge" i18n>File Size Small -> Large</mat-option>
<mat-option value="largeToSmall" i18n>File Size Large -> Small</mat-option>
</mat-select>
</mat-form-field>
<div class="assets">
<div class="asset-items-container">
<ul class="asset-items">
<ng-container *ngFor="let assetItem of projectAssets.files">
<li
*ngIf="
allowedFileTypes.includes('any') || allowedFileTypes.includes(assetItem.fileType)
"
class="asset-item cursor-pointer"
(mouseover)="previewAsset(assetItem)"
[ngStyle]="{ 'background-color': selectedAssetItem === assetItem ? 'yellow' : '' }"
fxLayout="row"
fxLayoutAlign="start center"
fxLayoutGap="10px"
>
<button mat-stroked-button *ngIf="isPopup" (click)="chooseAsset(assetItem)" i18n>
Choose
</button>
<span>{{ assetItem.fileName }} ({{ assetItem.fileSize | filesize }})</span>
<span *ngIf="!assetItem.used">
<span class="red" i18n>(Not Used)</span>
</span>
<div fxFlex></div>
<button
mat-icon-button
(click)="downloadAsset(assetItem)"
matTooltip="Download"
matTooltipPosition="above"
i18n-matTooltip
>
<mat-icon>file_download</mat-icon>
</button>
<button
mat-icon-button
(click)="deleteAsset(assetItem)"
matTooltip="Delete"
matTooltipPosition="above"
i18n-matTooltip
>
<mat-icon>delete</mat-icon>
</button>
</li>
</ng-container>
</ul>
</div>
<div class="asset-preview">
<img *ngIf="assetIsImage" [src]="previewAssetURL" class="max-width-400" />
<video *ngIf="assetIsVideo" class="max-width-400" controls>
<source [src]="previewAssetURL" type="video/mp4" />
</video>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.root {
padding: 0px 16px;
}

.drop-box {
background: #F8F8F8;
border: 5px dashed #DDD;
height: 100px;
text-align: center;
padding-top: 30px;
margin-top: 10px;
margin-bottom: 10px;
bottom: 0px;
position: relative;
cursor: pointer;
}

.file-input {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}

.storage-usage-message {
margin-bottom: 10px;
}

.assets {
display: flex;
}

.asset-items-container {
flex: 1;
height: 500px;
overflow-y: scroll;
}

.asset-items {
padding: 0px;
}

.asset-item {
list-style-type: none;
}

.asset-preview {
flex: 1;
}

.mat-icon {
margin: 0px;
}

.red {
color: red;
}

.background-green {
background-color: lightgreen;
}

.background-pink {
background-color: lightpink;
}

.max-width-400 {
max-width: 400px;
}

.cursor-pointer {
cursor: pointer;
}
Loading

0 comments on commit 4f58aad

Please sign in to comment.