From 444ee0481d49608255a3b595f88de9c0b1712950 Mon Sep 17 00:00:00 2001 From: Artur Date: Sat, 18 Jan 2025 12:10:10 +0100 Subject: [PATCH] removing friendly pages --- deploy-this/compres-with-structure.sh | 1 + deploy-this/compress-with-structure.py | 51 +++++++++++++++++++ deploy-this/convert-img-by-image-magic.sh | 42 +++++++++++++++ deploy-this/convert-img.js | 33 ++++++++++++ package-lock.json | 10 ++++ package.json | 3 +- src/app/about-me/about-me.component.html | 8 +-- src/app/app.component.html | 1 - src/app/app.routes.ts | 5 -- .../asset-calculator.component.css | 6 +++ .../asset-calculator.component.html | 10 +++- .../asset-calculator.component.ts | 36 +++++++++---- src/app/assets/asset.ts | 13 ++++- 13 files changed, 195 insertions(+), 24 deletions(-) create mode 100755 deploy-this/compres-with-structure.sh create mode 100644 deploy-this/compress-with-structure.py create mode 100755 deploy-this/convert-img-by-image-magic.sh create mode 100644 deploy-this/convert-img.js diff --git a/deploy-this/compres-with-structure.sh b/deploy-this/compres-with-structure.sh new file mode 100755 index 0000000..9c64655 --- /dev/null +++ b/deploy-this/compres-with-structure.sh @@ -0,0 +1 @@ +python3 compress-with-structure.py \ No newline at end of file diff --git a/deploy-this/compress-with-structure.py b/deploy-this/compress-with-structure.py new file mode 100644 index 0000000..8dc7521 --- /dev/null +++ b/deploy-this/compress-with-structure.py @@ -0,0 +1,51 @@ +import os +from PIL import Image, UnidentifiedImageError +from shutil import copy2 + +# Ścieżki katalogów +input_folder = "src/main/resources/static/zaklik-public-images" # Folder źródłowy +output_folder = "src/main/resources/static/zaklik-public-images" # Folder docelowy + +# Funkcja kompresująca obrazy +def compress_image(input_path, output_path): + try: + with Image.open(input_path) as img: + img_format = img.format # Zachowaj format pliku + if img_format in ["JPEG", "PNG"]: + img.save(output_path, optimize=True, quality=15) + else: + copy2(input_path, output_path) # Kopiuj bez zmian, jeśli format nie jest obsługiwany + except UnidentifiedImageError: + print(f"Nie rozpoznano formatu obrazu: {input_path}") + +# Funkcja do przetwarzania plików w folderze +def process_folder(input_folder, output_folder): + for root, _, files in os.walk(input_folder): + for file in files: + # Ścieżka do pliku wejściowego + input_path = os.path.join(root, file) + + # Tworzenie ścieżki docelowej z odpowiednią strukturą katalogów + relative_path = os.path.relpath(root, input_folder) + target_dir = os.path.join(output_folder, relative_path) + os.makedirs(target_dir, exist_ok=True) + + # Obsługa plików już skompresowanych + if "(compressed)" in file: + continue + if "properties" in file: + continue + # Generowanie nazwy pliku wyjściowego + name, ext = os.path.splitext(file) + output_file = f"{name}(compressed){ext}" + output_path = os.path.join(target_dir, output_file) + # Sprawdzenie, czy skompresowany plik już istnieje + if os.path.exists(output_path): + print(f"Pominięto, plik już istnieje: {output_path}") + continue + # Kompresja pliku + print(f"Kompresowanie: {input_path} -> {output_path}") + compress_image(input_path, output_path) + +# Wykonanie skryptu +process_folder(input_folder, output_folder) diff --git a/deploy-this/convert-img-by-image-magic.sh b/deploy-this/convert-img-by-image-magic.sh new file mode 100755 index 0000000..4a19dda --- /dev/null +++ b/deploy-this/convert-img-by-image-magic.sh @@ -0,0 +1,42 @@ +INPUT_DIR="./src/main/resources/static/zaklik-public-images" # Folder z oryginalnymi obrazami +OUTPUT_DIR="./src/main/resources/static/zaklik-public-images-generated" # Główny folder do zapisu obrazów w nowych formatach + +# Iteracja po wszystkich plikach w katalogu wejściowym i jego podkatalogach +find "$INPUT_DIR" -type f | while read -r file; do + # Relatywna ścieżka pliku w katalogu wejściowym + relative_path="${file#$INPUT_DIR/}" + + # Ścieżka do katalogu docelowego + target_dir="$OUTPUT_DIR/$(dirname "$relative_path")" + + # Nazwa pliku bez rozszerzenia + filename=$(basename "$file" | cut -f 1 -d '.') + + # Ścieżki docelowych plików w formatach WebP i AVIF + webp_file="$target_dir/$filename.webp" + avif_file="$target_dir/$filename.avif" + + # Sprawdzenie, czy oba pliki już istnieją + if [ -f "$webp_file" ] && [ -f "$avif_file" ]; then + echo "Pomijam plik: $file (już skompresowany)" + continue + fi + + # Tworzenie podkatalogu w katalogu docelowym + mkdir -p "$target_dir" + + # Konwersja do WebP (jeśli plik nie istnieje) + if [ ! -f "$webp_file" ]; then + convert "$file" -quality 80 "$webp_file" + echo "Skompresowano do WebP: $webp_file" + fi + + # Konwersja do AVIF (jeśli plik nie istnieje) + if [ ! -f "$avif_file" ]; then + convert "$file" -quality 80 "$avif_file" + echo "Skompresowano do AVIF: $avif_file" + fi +done + +echo "Konwersja zakończona." + diff --git a/deploy-this/convert-img.js b/deploy-this/convert-img.js new file mode 100644 index 0000000..efd124f --- /dev/null +++ b/deploy-this/convert-img.js @@ -0,0 +1,33 @@ +const sharp = require('sharp'); +const fs = require('fs'); +const path = require('path'); + +const inputDir = './src/main/resources/static/zaklik-public-images'; // Folder z oryginalnymi obrazami +const outputDir = './src/main/resources/static/main-images/optimized-by-sharp'; // Folder do zapisu obrazów w nowych formatach + +const formats = ['webp', 'avif']; + +fs.readdir(inputDir, (err, files) => { + if (err) { + console.error('Error reading input directory:', err); + return; + } + + files.forEach(file => { + const inputFile = path.join(inputDir, file); + const fileName = path.parse(file).name; + + formats.forEach(format => { + const outputFile = path.join(outputDir, `${fileName}.${format}`); + sharp(inputFile) + .toFormat(format, { quality: 80 }) + .toFile(outputFile, (err, info) => { + if (err) { + console.error(`Error converting ${file} to ${format}:`, err); + } else { + console.log(`Converted ${file} to ${format} format.`); + } + }); + }); + }); +}); diff --git a/package-lock.json b/package-lock.json index 31cf58d..93434a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@ngx-translate/core": "^16.0.3", "@ngx-translate/http-loader": "^16.0.0", "bootstrap": "^5.3.3", + "date-fns": "^4.1.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -9423,6 +9424,15 @@ "integrity": "sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==", "dev": true }, + "node_modules/date-fns": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz", + "integrity": "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/kossnocorp" + } + }, "node_modules/date-format": { "version": "4.0.14", "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", diff --git a/package.json b/package.json index cd44407..c799b01 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@ngx-translate/core": "^16.0.3", "@ngx-translate/http-loader": "^16.0.0", "bootstrap": "^5.3.3", + "date-fns": "^4.1.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -47,4 +48,4 @@ "typescript-eslint": "8.10.0", "vite": "^5.4.10" } -} \ No newline at end of file +} diff --git a/src/app/about-me/about-me.component.html b/src/app/about-me/about-me.component.html index 55a5d9f..7c8f103 100644 --- a/src/app/about-me/about-me.component.html +++ b/src/app/about-me/about-me.component.html @@ -8,19 +8,19 @@
Wrocław
- + envelope kusartur@gmail.com
- +48 511 116 016 + telephone +48 511 116 016
Linkedin + width="30" height="20" src="icons/linkedin.svg" alt="linkedin" >Linkedin
diff --git a/src/app/app.component.html b/src/app/app.component.html index 0927ddc..1f18c0e 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -47,7 +47,6 @@ {{ 'topBar.aboutMe' | translate }} {{ 'topBar.depreciationCalculator' | translate }} {{ 'topBar.courses' | translate }} - {{ 'topBar.friendlyPages' | translate }} diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index f79bc8c..0cf9674 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -36,11 +36,6 @@ export const routes: Routes = [ path: "fixed-asset", title:"Środki trwałe", component: FixedAssetComponent - }, - { - path: "friendly-pages", - title:"Zaprzyjaznione strony", - component: FriendlyPagesComponent } diff --git a/src/app/asset-calculator/asset-calculator.component.css b/src/app/asset-calculator/asset-calculator.component.css index e69de29..18384a1 100644 --- a/src/app/asset-calculator/asset-calculator.component.css +++ b/src/app/asset-calculator/asset-calculator.component.css @@ -0,0 +1,6 @@ +.month-picker .mat-calendar-body-cell-content { + display: none; /* Ukrywa dni */ +} +.month-picker .mat-calendar-body-cell-content:not(.mat-calendar-body-disabled) { +display: flex; +} \ No newline at end of file diff --git a/src/app/asset-calculator/asset-calculator.component.html b/src/app/asset-calculator/asset-calculator.component.html index 7a28b78..1c2b934 100644 --- a/src/app/asset-calculator/asset-calculator.component.html +++ b/src/app/asset-calculator/asset-calculator.component.html @@ -44,12 +44,18 @@
+
+
- - + + {{ 'asset-calculator.startOfDepreciation' | translate }} + + + +
diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts index 88e103e..72b5bf1 100644 --- a/src/app/asset-calculator/asset-calculator.component.ts +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -4,11 +4,16 @@ import { Asset, AssetPlanPosition, TypeDepreciation, YearMonth, AssetLifeChange, import { AssetService } from '../assets/service/asset.service'; import { TranslateModule, TranslateService } from "@ngx-translate/core"; import { FormsModule } from '@angular/forms'; +import { MatDatepicker, MatDatepickerModule } from '@angular/material/datepicker'; +import { MatNativeDateModule } from '@angular/material/core'; +import { MatInputModule } from '@angular/material/input'; +import { format, parse, addMonths, isAfter } from 'date-fns'; + interface FormValues { initialValueAsset:number; rate: number; - startDepreciation: string; + startDepreciation: Date; typeDepreciation: TypeDepreciation; factor: number; } @@ -17,7 +22,6 @@ class AssetLifeChangeWrapper{ when = signal ( YearMonth.todayTxt()); initial = signal( 0 ); - constructor( assetLifeChange : AssetLifeChange ){ this.set(assetLifeChange); } @@ -38,7 +42,11 @@ const NAME_IN_STORAGE = 'assetForCalculator'; @Component({ selector: 'app-asset-calculator', standalone: true, - imports: [DecimalPipe, TranslateModule, FormsModule], + imports: [DecimalPipe, TranslateModule, FormsModule, MatDatepickerModule, MatNativeDateModule, MatInputModule], + providers: [ + MatDatepickerModule, + MatNativeDateModule + ], templateUrl: "asset-calculator.component.html", styleUrls: ['asset-calculator.component.css'] }) @@ -50,7 +58,7 @@ export class AssetCalculatorComponent { initialValueAsset = signal ( 6000 ); rate = signal ( 20 ); - startDepreciation = signal ( YearMonth.today().toString() ); + startDepreciation = signal ( new Date() ); typeDepreciation = signal ( TypeDepreciation.linear ); factor = signal ( 2 ); @@ -74,6 +82,8 @@ export class AssetCalculatorComponent { effect( () => this.reCalculate( ) ) } + + private storage = { load: (key: string) => { try { @@ -97,7 +107,6 @@ export class AssetCalculatorComponent { this.restoreState(); } - ngOnDestroy(): void { const asset = this.controlsToAsset( ); if( null != asset){ @@ -114,7 +123,6 @@ export class AssetCalculatorComponent { this.storage.save(NAME_IN_STORAGE, asset); } - private assetToControls( asset : Asset ) { if( asset.life.length > 0 ){ this.updateBatch(asset); @@ -126,7 +134,7 @@ private updateBatch(asset: Asset) { const method0 = asset.depreciationMethods[0]; this.initialValueAsset.set(firstLife.initial); - this.startDepreciation.set(YearMonth.toTxt(firstLife.when)); + this.startDepreciation.set(YearMonth.toDate(firstLife.when)); this.rate.set(method0.rate); this.typeDepreciation.set(method0.type); this.factor.set(method0.factor); @@ -137,13 +145,12 @@ private updateBatch(asset: Asset) { this.lifeChangesSignal.set(lifeChanges); } - private controlsToAsset(): Asset { const formValues = this.formValues(); const lifeChanges = this.lifeChangesSignal(); - const when = YearMonth.from( formValues.startDepreciation ); + const when = YearMonth.fromDate( formValues.startDepreciation ); const asset = new Asset( when ); const method = new AssetDepreciationMethod( when.year, formValues.rate, formValues.typeDepreciation, formValues.factor ); @@ -200,7 +207,7 @@ private controlsToAsset(): Asset { // Method to add a life change addLifeChange( ) { const assetLifeChange2 : AssetLifeChange - = new AssetLifeChange( YearMonth.from( this.formValues().startDepreciation ), 1000, 0, 0 ); + = new AssetLifeChange( YearMonth.fromDate( this.formValues().startDepreciation ), 1000, 0, 0 ); return this.addLifeChange2( assetLifeChange2 ); } @@ -218,6 +225,15 @@ private controlsToAsset(): Asset { ); } + updateDateFromInput(inputValue: string) { + // Konwersja stringa 'YYYY-MM' na Date + const parsedDate = parse(inputValue, 'yyyy-MM', new Date()); + this.startDepreciation.set(parsedDate); + } + onMonthSelected(event: Date, datepicker: MatDatepicker) { + this.startDepreciation.set(event); // Aktualizacja pola w formularzu + datepicker.close(); + } } diff --git a/src/app/assets/asset.ts b/src/app/assets/asset.ts index 01d633c..831b697 100644 --- a/src/app/assets/asset.ts +++ b/src/app/assets/asset.ts @@ -10,14 +10,22 @@ export class YearMonth{ return new YearMonth( year, month ); } + static fromDate( date: Date) { + + return new YearMonth( date.getFullYear(), date.getMonth()+1 ); + } + readonly year : number ; readonly month : number ; constructor( year:number, month : number ){ this.year = year; this.month = month; - } + } + toDate(){ + return new Date(this.year, this.month-1, 1); + } static today( ):YearMonth{ const today = new Date(); @@ -31,6 +39,9 @@ export class YearMonth{ static toTxt( ym : YearMonth ):string{ return ym.year + '-' + String(ym.month).padStart(2, '0');; } + static toDate( ym : YearMonth) : Date{ + return new Date(ym.year, ym.month-1, 1); + } toJSON() { return { year: this.year, month: this.month };