Skip to content

Commit

Permalink
refactor: image settings (#1460)
Browse files Browse the repository at this point in the history
Co-authored-by: Irmantas Kaukas <irmastnt@gmail.com>
  • Loading branch information
derschnee68 and irmastnt committed Feb 13, 2024
1 parent 6cc1ada commit 238b979
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 212 deletions.
4 changes: 4 additions & 0 deletions apps/dsp-app/src/app/app.module.ts
Expand Up @@ -81,6 +81,8 @@ import { CreateProjectFormPageComponent } from './project/create-project-form-pa
import { DataModelsComponent } from './project/data-models/data-models.component';
import { DescriptionComponent } from './project/description/description.component';
import { EditProjectFormPageComponent } from './project/edit-project-form-page/edit-project-form-page.component';
import { ImageDisplayAbsoluteComponent } from './project/image-settings/image-display-absolute.component';
import { ImageDisplayRatioComponent } from './project/image-settings/image-display-ratio.component';
import { ImageSettingsComponent } from './project/image-settings/image-settings.component';
import { ActionBubbleComponent } from './project/list/action-bubble/action-bubble.component';
import { ListItemComponent } from './project/list/list-item/list-item.component';
Expand Down Expand Up @@ -232,6 +234,8 @@ export function httpLoaderFactory(httpClient: HttpClient) {
GridComponent,
HeaderComponent,
HelpComponent,
ImageDisplayAbsoluteComponent,
ImageDisplayRatioComponent,
IntermediateComponent,
IntervalInputComponent,
IntervalValueComponent,
Expand Down
@@ -0,0 +1,85 @@
import { Component, Input } from '@angular/core';

@Component({
selector: 'app-image-display-absolute',
template: ` <div class="frame">
<div class="text">Example image with width: {{ bigWidth }}px</div>
<div
[ngStyle]="{ width: (widthPx / bigWidth) * 300 + 'px', height: (widthPx / bigWidth) * 200 + 'px' }"
class="back-rectangle">
<div class="arrow left-arrow"></div>
<div class="arrow right-arrow"></div>
<div class="helper">
{{ widthPx }}
px
</div>
</div>
</div>`,
styles: [
`
.frame {
background: gray;
width: 300px;
height: 200px;
position: relative;
}
.text {
width: 100%;
text-align: center;
position: absolute;
top: 20px;
}
.back-rectangle {
background: darkgray;
bottom: 0;
right: 0;
position: absolute;
}
.helper {
position: absolute;
bottom: -40px;
right: 0;
text-align: center;
width: 100%;
min-width: 100px;
}
.arrow {
position: absolute;
height: 1px; /* Adjust the height of the stick */
background-color: red; /* Adjust the color of the stick */
right: 0;
bottom: -20px;
width: 100%;
}
.left-arrow::before,
.right-arrow::before {
content: '';
position: absolute;
top: -5px;
width: 0;
height: 0;
border-top: 5px solid transparent; /* Adjust the height of the arrow */
border-bottom: 5px solid transparent; /* Adjust the height of the arrow */
}
.left-arrow::before {
right: 0;
border-left: 10px solid red; /* Adjust the width and color of the arrow */
}
.right-arrow::before {
left: 0;
border-right: 10px solid red; /* Adjust the width and color of the arrow */
}
`,
],
})
export class ImageDisplayAbsoluteComponent {
@Input() widthPx: number;
readonly bigWidth = 2048;
}
@@ -0,0 +1,74 @@
import { Component, Input } from '@angular/core';

@Component({
selector: 'app-image-display-ratio',
template: ` <div class="frame">
<div [ngStyle]="{ width: ratio * 300 + 'px', height: ratio * 200 + 'px' }" class="back-rectangle">
<div class="arrow left-arrow"></div>
<div class="arrow right-arrow"></div>
<div class="helper">Ratio: {{ Math.ceil(ratio * 100) }}%</div>
</div>
</div>`,
styles: [
`
.frame {
background: gray;
width: 300px;
height: 200px;
position: relative;
}
.back-rectangle {
background: darkgray;
bottom: 0;
right: 0;
position: absolute;
}
.helper {
min-width: 100px;
position: absolute;
bottom: -30px;
right: 0;
text-align: center;
width: 100%;
}
.arrow {
position: absolute;
height: 1px; /* Adjust the height of the stick */
background-color: red; /* Adjust the color of the stick */
right: 0;
bottom: 0px;
width: 119%;
transform: rotate(33deg);
transform-origin: bottom right;
}
.left-arrow::before,
.right-arrow::before {
content: '';
position: absolute;
top: -5px;
width: 0;
height: 0;
border-top: 5px solid transparent; /* Adjust the height of the arrow */
border-bottom: 5px solid transparent; /* Adjust the height of the arrow */
}
.left-arrow::before {
right: 0;
border-left: 10px solid red; /* Adjust the width and color of the arrow */
}
.right-arrow::before {
left: 0;
border-right: 10px solid red; /* Adjust the width and color of the arrow */
}
`,
],
})
export class ImageDisplayRatioComponent {
@Input() ratio: number;
protected readonly Math = Math;
}
Expand Up @@ -2,91 +2,83 @@
<dasch-swiss-app-progress-indicator *ngIf="isProjectsLoading$ | async"></dasch-swiss-app-progress-indicator>
<div class="content large middle" *ngIf="(isProjectsLoading$ | async) === false">
<div>
<form *ngIf="form" class="form-content" [formGroup]="form">
<div class="large-field section">
<mat-slide-toggle formControlName="isWatermark">
{{ 'appLabels.form.project.imageSettings.isWatermark' | translate }}
</mat-slide-toggle>
<div class="mb-6">
<mat-slide-toggle [(ngModel)]="isWatermark">
{{ 'appLabels.form.project.imageSettings.isWatermark' | translate }}
</mat-slide-toggle>
</div>
<div class="mb-2">
<mat-slide-toggle [(ngModel)]="allowRestriction">
{{ 'appLabels.form.project.imageSettings.restrictImageSize' | translate }}
</mat-slide-toggle>
</div>
<div *ngIf="allowRestriction">
<div style="margin-bottom: 16px">
<mat-radio-group [(ngModel)]="isPercentageSize" [ngModelOptions]="{standalone: true}">
<mat-radio-button [value]="true">
{{ 'appLabels.form.project.imageSettings.ratio' | translate }}
</mat-radio-button>
<mat-radio-button [value]="false">
{{ 'appLabels.form.project.imageSettings.fixed' | translate }}
</mat-radio-button>
</mat-radio-group>
</div>
<div class="large-field" *ngIf="form.controls.isWatermark.value">
<mat-slide-toggle formControlName="restrictImageSize">
{{ 'appLabels.form.project.imageSettings.restrictImageSize' | translate }}
</mat-slide-toggle>
</div>
<ng-container *ngIf="form.controls.restrictImageSize.value && form.controls.isWatermark.value">
<div class="content-container">
<div class="large-field aspect">
<mat-radio-group formControlName="aspect">
<mat-radio-button [value]="true">
{{ 'appLabels.form.project.imageSettings.ratio' | translate }}
</mat-radio-button>
<mat-radio-button [value]="false">
{{ 'appLabels.form.project.imageSettings.fixed' | translate }}
</mat-radio-button>
</mat-radio-group>
</div>
<div *ngIf="form.controls.aspect.value" [@replaceAnimation]>
<div class="large-field">
<mat-label>
{{ 'appLabels.form.project.imageSettings.percentageValue' | translate }}: {{ percentageSlider.value}}%
</mat-label>
</div>
<mat-slider
min="10"
max="100"
step="10"
showTickMarks
discrete
[displayWith]="formatPercentageLabel"
ngDefaultControl
formControlName="percentage">
<input #percentageSlider matSliderThumb [value]="form.controls.percentage.value" />
</mat-slider>

<div *ngIf="isPercentageSize" [@replaceAnimation] class="flex-with-gap">
<section class="child">
<div class="large-field">
<mat-label>
{{ 'appLabels.form.project.imageSettings.percentageValue' | translate }} : {{ percentageSlider.value }}%
</mat-label>
</div>
<div *ngIf="!form.controls.aspect.value" [@replaceAnimation]>
<div class="large-field">
<mat-label>
{{ 'appLabels.form.project.imageSettings.absoluteWidth' | translate }}: {{
projectImageSettings.absoluteWidth }} px
</mat-label>
</div>
<mat-slider
[min]="0"
[max]="4"
[step]="1"
showTickMarks
[displayWith]="formatAbsoluteLabel"
discrete
ngDefaultControl
formControlName="absoluteWidthIndex">
<input
(valueChange)="absoluteSliderChange($event)"
[value]="absoluteWidthIndex(projectImageSettings.absoluteWidth)"
matSliderThumb />
</mat-slider>

<mat-slider
min="10"
max="90"
step="10"
showTickMarks
discrete
[displayWith]="formatPercentageLabel"
ngDefaultControl>
<input #percentageSlider matSliderThumb [(value)]="percentage" />
</mat-slider>
</section>
<app-image-display-ratio
*ngIf="isPercentageSize"
[ratio]="percentage/100"
class="child"></app-image-display-ratio>
</div>

<div *ngIf="!isPercentageSize" [@replaceAnimation] class="flex-with-gap">
<section>
<div class="large-field">
<mat-label>
{{ 'appLabels.form.project.imageSettings.absoluteWidth' | translate }}: {{ fixedWidth }} px
</mat-label>
</div>
</div>
<div class="content-sidebar" *ngIf="form.controls.restrictImageSize.value && form.controls.isWatermark.value">
<img
[@replaceAnimation]
*ngIf="!form.controls.aspect.value"
src="assets/images/image-setting-absolute.png"
[alt]="'appLabels.form.project.imageSettings.absolute' | translate" />
<img
[@replaceAnimation]
*ngIf="form.controls.aspect.value"
src="assets/images/image-setting-percentage.png"
[alt]="'appLabels.form.project.imageSettings.percentage' | translate" />
</div>
</ng-container>
</form>
<mat-slider
[min]="0"
[max]="4"
[step]="1"
showTickMarks
[displayWith]="formatAbsoluteLabel"
discrete
ngDefaultControl>
<input
(valueChange)="absoluteSliderChange($event)"
[value]="absoluteWidthIndex(fixedWidth)"
matSliderThumb />
</mat-slider>
</section>
<app-image-display-absolute *ngIf="!isPercentageSize" [widthPx]="fixedWidth"></app-image-display-absolute>
</div>
</div>
</div>
<div class="action-buttons">
<div class="action-buttons mt-2">
<button
mat-raised-button
type="submit"
color="primary"
[disabled]="form?.invalid"
(click)="onSubmit()"
appLoadingButton
[isLoading]="isProjectsLoading$ | async">
Expand Down
@@ -1,34 +1,27 @@
@use '../../../styles/responsive' as *;

@use '../../../styles/responsive' as *;

.content {
.form-content {
width: 100%;
}
.mat-mdc-slider {
width: 100%;
}

.content-sidebar {
display: inline-block;
width: 50%;
}
.action-buttons {
display: flex;
justify-content: space-between;
}

.content-container {
display: inline-block;
padding-right: 32px;
vertical-align: top;
max-width: 298px;
@media (min-width: 1000px) {
.flex-with-gap {
display: flex;
gap: 48px
}
}

.section {
padding-bottom: 32px;
}
.mb-2 {
margin-bottom: 16px;
}

.mat-mdc-slider {
width: 100%;
}
.mb-6 {
margin-bottom: 48px;
}

.action-buttons {
display: flex;
justify-content: space-between;
}
.mt-2 {
margin-top: 16px;
}

0 comments on commit 238b979

Please sign in to comment.