-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from e-picsa/ft-farmer-photo-storage
ft(farmer-activity) Support for photo storage
- Loading branch information
Showing
29 changed files
with
495 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './photo-debug/photo-debug.component'; | ||
export * from './photo-input/photo-input.component'; | ||
export * from './photo-list/photo-list.component'; | ||
export * from './photo-view/photo-view.component'; |
5 changes: 5 additions & 0 deletions
5
libs/shared/src/features/photo/components/photo-debug/photo-debug.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="page-content"> | ||
<h2>Photos Debug</h2> | ||
<picsa-photo-list /> | ||
<picsa-photo-input album="debug" style="margin-top: 2rem;" /> | ||
</div> |
Empty file.
22 changes: 22 additions & 0 deletions
22
libs/shared/src/features/photo/components/photo-debug/photo-debug.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PhotoDebugComponent } from './photo-debug.component'; | ||
|
||
describe('PhotoDebugComponent', () => { | ||
let component: PhotoDebugComponent; | ||
let fixture: ComponentFixture<PhotoDebugComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [PhotoDebugComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(PhotoDebugComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
libs/shared/src/features/photo/components/photo-debug/photo-debug.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { PhotoInputComponent } from '../photo-input/photo-input.component'; | ||
import { PhotoListComponent } from '../photo-list/photo-list.component'; | ||
import { PhotoViewComponent } from '../photo-view/photo-view.component'; | ||
|
||
@Component({ | ||
selector: 'picsa-photo-debug', | ||
standalone: true, | ||
imports: [PhotoInputComponent, PhotoListComponent, PhotoViewComponent], | ||
templateUrl: './photo-debug.component.html', | ||
styleUrl: './photo-debug.component.scss', | ||
}) | ||
export class PhotoDebugComponent {} |
6 changes: 6 additions & 0 deletions
6
libs/shared/src/features/photo/components/photo-input/photo-input.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<button mat-button mat-raised-button class="footer-button" color="primary" (click)="takeOrChoosePicture()"> | ||
<span> | ||
<mat-icon class="photo-icon">add_a_photo</mat-icon> | ||
{{ 'Add Photo' | translate }} | ||
</span> | ||
</button> |
5 changes: 5 additions & 0 deletions
5
libs/shared/src/features/photo/components/photo-input/photo-input.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.photo-icon { | ||
position: relative; | ||
top: 2px; | ||
right: 5px; | ||
} |
54 changes: 54 additions & 0 deletions
54
libs/shared/src/features/photo/components/photo-input/photo-input.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Component, ElementRef, input, ViewChild } from '@angular/core'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; | ||
import { Capacitor } from '@capacitor/core'; | ||
|
||
import { PicsaTranslateModule } from '../../../../modules/translate'; | ||
import { PhotoService } from '../../photo.service'; | ||
import { ENTRY_TEMPLATE } from '../../schema'; | ||
|
||
@Component({ | ||
selector: 'picsa-photo-input', | ||
templateUrl: './photo-input.component.html', | ||
styleUrls: ['./photo-input.component.scss'], | ||
standalone: true, | ||
imports: [PicsaTranslateModule, MatButtonModule, MatIconModule], | ||
}) | ||
export class PhotoInputComponent { | ||
@ViewChild('fileInput') fileInput: ElementRef; | ||
/** Store photo within a specific named album */ | ||
album = input.required<string>(); | ||
/** | ||
* Name to store photo as. If unspecified will be randomly generated | ||
* If duplicate will override | ||
*/ | ||
name = input<string>(); | ||
|
||
constructor(private photoService: PhotoService) {} | ||
|
||
async ngOnInit() { | ||
await this.photoService.init(); | ||
} | ||
|
||
// this method will be called when a user clicks the camera button | ||
async takeOrChoosePicture() { | ||
const platform = Capacitor.getPlatform(); | ||
const source = platform === 'web' ? CameraSource.Photos : CameraSource.Prompt; | ||
|
||
const image = await Camera.getPhoto({ | ||
quality: 90, | ||
allowEditing: false, | ||
resultType: CameraResultType.Uri, | ||
source: source, | ||
}); | ||
|
||
if (image.webPath) { | ||
const fetchRes = await fetch(image.webPath); | ||
const blob = await fetchRes.blob(); | ||
const entry = ENTRY_TEMPLATE(this.album(), this.name()); | ||
await this.photoService.savePhoto(entry, blob); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
libs/shared/src/features/photo/components/photo-list/photo-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="photo-grid"> | ||
@for(photo of photos(); track photo.id;){ | ||
<picsa-photo-view [photo]="photo"></picsa-photo-view> | ||
} | ||
</div> | ||
@if(photos().length ===0){ | ||
<div class="no-photos-message">{{ 'No photos added' | translate }}</div> | ||
} |
6 changes: 6 additions & 0 deletions
6
libs/shared/src/features/photo/components/photo-list/photo-list.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.photo-grid { | ||
display: grid; | ||
grid-auto-rows: 120px; | ||
grid-template-columns: repeat(auto-fit, 120px); | ||
gap: 8px; | ||
} |
22 changes: 22 additions & 0 deletions
22
libs/shared/src/features/photo/components/photo-list/photo-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PhotoListComponent } from './photo-list.component'; | ||
|
||
describe('PhotoListComponent', () => { | ||
let component: PhotoListComponent; | ||
let fixture: ComponentFixture<PhotoListComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [PhotoListComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(PhotoListComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
libs/shared/src/features/photo/components/photo-list/photo-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, computed, input } from '@angular/core'; | ||
|
||
import { PicsaTranslateModule } from '../../../../modules'; | ||
import { PhotoService } from '../../photo.service'; | ||
import { PhotoViewComponent } from '../photo-view/photo-view.component'; | ||
|
||
@Component({ | ||
selector: 'picsa-photo-list', | ||
standalone: true, | ||
imports: [PhotoViewComponent, PicsaTranslateModule], | ||
templateUrl: './photo-list.component.html', | ||
styleUrl: './photo-list.component.scss', | ||
}) | ||
export class PhotoListComponent { | ||
album = input<string>(); | ||
|
||
photos = computed(() => { | ||
const album = this.album(); | ||
const photoDocs = this.service.photos(); | ||
return album ? photoDocs.filter((d) => d.album === album) : photoDocs; | ||
}); | ||
|
||
constructor(private service: PhotoService) {} | ||
} |
10 changes: 10 additions & 0 deletions
10
libs/shared/src/features/photo/components/photo-view/photo-view.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@if(uri()){ | ||
<img [src]="uri()" /> | ||
<!-- TODO - show delete option on long press --> | ||
<button mat-icon-button (click)="promptDelete()" color="secondary" class="delete-button"> | ||
<mat-icon>close</mat-icon> | ||
</button> | ||
|
||
} @if(errorMsg()){ | ||
<div class="error-msg">{{ errorMsg() }}</div> | ||
} |
28 changes: 28 additions & 0 deletions
28
libs/shared/src/features/photo/components/photo-view/photo-view.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
:host { | ||
display: block; | ||
position: relative; | ||
} | ||
img { | ||
height: 100%; | ||
width: 100%; | ||
object-fit: cover; | ||
} | ||
button.delete-button.mat-mdc-icon-button.mat-mdc-button-base { | ||
--mdc-icon-button-state-layer-size: 32px; | ||
padding: 4px; | ||
border-radius: 0; | ||
position: absolute; | ||
top: 0px; | ||
right: 0px; | ||
color: rgb(0 0 0 / 50%); | ||
background: rgb(255 255 255 / 20%); | ||
} | ||
.error-msg { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
text-align: center; | ||
height: 100%; | ||
border: 1px solid var(--color-light); | ||
} |
22 changes: 22 additions & 0 deletions
22
libs/shared/src/features/photo/components/photo-view/photo-view.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PhotoViewComponent } from './photo-view.component'; | ||
|
||
describe('PhotoViewComponent', () => { | ||
let component: PhotoViewComponent; | ||
let fixture: ComponentFixture<PhotoViewComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [PhotoViewComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(PhotoViewComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.