add share collection as text
This commit is contained in:
1 parent
dbb00fdb61
commit
6b7cca1fe9
3 files changed
+45
-10
No files matched your search
@@ -15,21 +15,21 @@ export class CollectionService {
|
|||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
// get all lists
|
// get all collections
|
||||||
getCollections(): Observable<Collection[]> {
|
getCollections(): Observable<Collection[]> {
|
||||||
return this.http.get<Collection[]>(
|
return this.http.get<Collection[]>(
|
||||||
`${this.backend_apiUrl}/${this.apiAction}`
|
`${this.backend_apiUrl}/${this.apiAction}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a list by id
|
// get a collection by id
|
||||||
getCollection(collectionId: number): Observable<Collection> {
|
getCollection(collectionId: number): Observable<Collection> {
|
||||||
return this.http.get<Collection>(
|
return this.http.get<Collection>(
|
||||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new list
|
// Create a new collection
|
||||||
createCollection(collection: Collection): Observable<Collection> {
|
createCollection(collection: Collection): Observable<Collection> {
|
||||||
return this.http.post<Collection>(
|
return this.http.post<Collection>(
|
||||||
`${this.backend_apiUrl}/${this.apiAction}`,
|
`${this.backend_apiUrl}/${this.apiAction}`,
|
||||||
@@ -64,14 +64,14 @@ export class CollectionService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a list by ID
|
// Delete a collection by ID
|
||||||
deleteCollection(collectionId: number): Observable<any> {
|
deleteCollection(collectionId: number): Observable<any> {
|
||||||
return this.http.delete(
|
return this.http.delete(
|
||||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an entry to a list
|
// Add an entry to a collection
|
||||||
addEntryToCollection(
|
addEntryToCollection(
|
||||||
collectionId: number,
|
collectionId: number,
|
||||||
entryId: number
|
entryId: number
|
||||||
@@ -82,7 +82,7 @@ export class CollectionService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update an entry's order in a list
|
// Update an entry's order in a collection
|
||||||
updateEntryOrder(
|
updateEntryOrder(
|
||||||
collectionId: number,
|
collectionId: number,
|
||||||
entryId: number,
|
entryId: number,
|
||||||
@@ -94,7 +94,7 @@ export class CollectionService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove an entry from a list
|
// Remove an entry from a collection
|
||||||
removeEntryFromCollection(
|
removeEntryFromCollection(
|
||||||
collectionId: number,
|
collectionId: number,
|
||||||
entryId: number
|
entryId: number
|
||||||
|
|||||||
+2
-1
@@ -32,7 +32,8 @@
|
|||||||
</li>
|
</li>
|
||||||
<li><a class="dropdown-item" (click)="switchViewMode()">Switch View</a></li>
|
<li><a class="dropdown-item" (click)="switchViewMode()">Switch View</a></li>
|
||||||
<li><a class="dropdown-item" (click)="deleteCollection()">Delete</a></li>
|
<li><a class="dropdown-item" (click)="deleteCollection()">Delete</a></li>
|
||||||
<li><a class="dropdown-item" (click)="shareScreenshot()">Share (as image)</a></li>
|
<li><a class="dropdown-item" (click)="shareScreenshot()">Share (Image)</a></li>
|
||||||
|
<li><a class="dropdown-item" (click)="copyTitles()">Share (Text)</a></li>
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item" *ngIf="!collection.isUserCollection" (click)="refreshCollection()">Refresh
|
<a class="dropdown-item" *ngIf="!collection.isUserCollection" (click)="refreshCollection()">Refresh
|
||||||
Information
|
Information
|
||||||
|
|||||||
+36
-2
@@ -195,7 +195,7 @@ export class CollectionInfoPageComponent implements OnInit {
|
|||||||
this.screenshotService
|
this.screenshotService
|
||||||
.capture('gridDiv')
|
.capture('gridDiv')
|
||||||
.then((dataUrl) => {
|
.then((dataUrl) => {
|
||||||
this.copyToClipboard(dataUrl);
|
this.copyDataUrlToClipboard(dataUrl);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error capturing screenshot:', error);
|
console.error('Error capturing screenshot:', error);
|
||||||
@@ -205,7 +205,24 @@ export class CollectionInfoPageComponent implements OnInit {
|
|||||||
this.viewMode = oldViewMode;
|
this.viewMode = oldViewMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private copyToClipboard(dataUrl: string) {
|
async copyTitles() {
|
||||||
|
let str = `${this.collection.name}: \n`;
|
||||||
|
|
||||||
|
await this.collection.entries.forEach((entry) => {
|
||||||
|
const year = new Date(entry.release_date).getFullYear();
|
||||||
|
if (entry.is_tvseries) {
|
||||||
|
str += `${entry.title} (${year} - Seasons: ${
|
||||||
|
entry.seasons.length
|
||||||
|
})\n`;
|
||||||
|
} else {
|
||||||
|
str += `${entry.title} (${year})\n`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.copyTextToClipboard(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
private copyDataUrlToClipboard(dataUrl: string) {
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = dataUrl;
|
img.src = dataUrl;
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
@@ -221,6 +238,23 @@ export class CollectionInfoPageComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async copyTextToClipboard(text: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Create a Blob from the text
|
||||||
|
const blob = new Blob([text], { type: 'text/plain' });
|
||||||
|
|
||||||
|
// Create a ClipboardItem with the Blob
|
||||||
|
const item = new ClipboardItem({ 'text/plain': blob });
|
||||||
|
|
||||||
|
// Write the item to the clipboard
|
||||||
|
await navigator.clipboard.write([item]);
|
||||||
|
|
||||||
|
//console.log('Text copied to clipboard successfully!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to copy text to clipboard:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
refreshCollection() {
|
refreshCollection() {
|
||||||
this.collectionService.refreshCollection(this.collection.id).subscribe({
|
this.collectionService.refreshCollection(this.collection.id).subscribe({
|
||||||
next: (data) => {
|
next: (data) => {
|
||||||
|
|||||||
Reference in new issue
Block a user