Skip to content

Commit

Permalink
Merge pull request #18 from Trivernis/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Trivernis authored Feb 20, 2022
2 parents 84f36a6 + 18546ea commit 351f74b
Show file tree
Hide file tree
Showing 25 changed files with 122 additions and 105 deletions.
2 changes: 1 addition & 1 deletion mediarepo-daemon/Cargo.lock

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

2 changes: 1 addition & 1 deletion mediarepo-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default-members = ["mediarepo-core", "mediarepo-database", "mediarepo-logic", "m

[package]
name = "mediarepo-daemon"
version = "1.0.0-rc.4"
version = "1.0.0"
edition = "2018"
license = "gpl-3"
repository = "https://github.com/Trivernis/mediarepo-daemon"
Expand Down
40 changes: 38 additions & 2 deletions mediarepo-daemon/mediarepo-logic/src/dao/tag/mappings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use sea_orm::prelude::*;
use sea_orm::sea_query::Query;
use sea_orm::ActiveValue::Set;
use sea_orm::{DatabaseTransaction, TransactionTrait};

use mediarepo_core::error::RepoResult;
use mediarepo_database::entities::content_descriptor_tag;
use mediarepo_database::entities::{content_descriptor_tag, namespace, tag};

use crate::dao::tag::TagDao;

Expand Down Expand Up @@ -41,11 +42,15 @@ impl TagDao {

#[tracing::instrument(level = "debug", skip(self))]
pub async fn remove_mappings(&self, cd_ids: Vec<i64>, tag_ids: Vec<i64>) -> RepoResult<()> {
let trx = self.ctx.db.begin().await?;
content_descriptor_tag::Entity::delete_many()
.filter(content_descriptor_tag::Column::CdId.is_in(cd_ids))
.filter(content_descriptor_tag::Column::TagId.is_in(tag_ids))
.exec(&self.ctx.db)
.exec(&trx)
.await?;
delete_orphans(&trx).await?;

trx.commit().await?;

Ok(())
}
Expand All @@ -66,3 +71,34 @@ async fn get_existing_mappings(
.collect();
Ok(existing_mappings)
}

/// Deletes orphaned tag entries and namespaces from the database
async fn delete_orphans(trx: &DatabaseTransaction) -> RepoResult<()> {
tag::Entity::delete_many()
.filter(
tag::Column::Id.not_in_subquery(
Query::select()
.column(content_descriptor_tag::Column::TagId)
.from(content_descriptor_tag::Entity)
.group_by_col(content_descriptor_tag::Column::TagId)
.to_owned(),
),
)
.exec(trx)
.await?;

namespace::Entity::delete_many()
.filter(
namespace::Column::Id.not_in_subquery(
Query::select()
.column(tag::Column::NamespaceId)
.from(tag::Entity)
.group_by_col(tag::Column::NamespaceId)
.to_owned(),
),
)
.exec(trx)
.await?;

Ok(())
}
2 changes: 1 addition & 1 deletion mediarepo-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mediarepo-ui",
"version": "1.0.0-rc.4",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
2 changes: 1 addition & 1 deletion mediarepo-ui/src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion mediarepo-ui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "app"
version = "1.0.0-rc.4"
version = "1.0.0"
description = "The UI for the mediarepo media management tool"
authors = ["you"]
license = ""
Expand Down
6 changes: 3 additions & 3 deletions mediarepo-ui/src/api/api-types/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export type PropertyQuery = PropertyQueryStatus

export type PropertyQueryStatus = { Status: FileStatus };
export type PropertyQueryFileSize = { FileSize: ValueComparator<number> };
export type PropertyQueryImportedTime = { ImportedTime: ValueComparator<Date> };
export type PropertyQueryChangedTime = { ChangedTime: ValueComparator<Date> };
export type PropertyQueryCreatedTime = { CreatedTime: ValueComparator<Date> };
export type PropertyQueryImportedTime = { ImportedTime: ValueComparator<string> };
export type PropertyQueryChangedTime = { ChangedTime: ValueComparator<string> };
export type PropertyQueryCreatedTime = { CreatedTime: ValueComparator<string> };
export type PropertyQueryTagCount = { TagCount: ValueComparator<number> };
export type PropertyQueryCd = { Cd: string };
export type PropertyQueryId = { Id: number };
Expand Down
20 changes: 15 additions & 5 deletions mediarepo-ui/src/api/models/File.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {FileBasicData, FileStatus} from "../api-types/files";
import {BehaviorSubject, Observable} from "rxjs";

export class File {

private statusSubject: BehaviorSubject<FileStatus>;

constructor(
private basicData: FileBasicData,
) {
this.statusSubject = new BehaviorSubject(basicData.status);
}

public get rawData(): FileBasicData {
Expand All @@ -18,15 +23,20 @@ export class File {
return this.basicData.cd;
}

public get status(): FileStatus {
return this.basicData.status;
public get status(): Observable<FileStatus> {
return this.statusSubject.asObservable();
}

public get mimeType(): string {
return this.basicData.mime_type;
}

public set status(value: FileStatus) {
public setStatus(value: FileStatus) {
this.basicData.status = value;
this.statusSubject.next(value);
}

public get mimeType(): string {
return this.basicData.mime_type;
public getStatus(): FileStatus {
return this.basicData.status;
}
}
27 changes: 19 additions & 8 deletions mediarepo-ui/src/api/models/FilterQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ export class FilterQueryBuilder {

public static importedTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery {
return filterQuery({
ImportedTime: valuesToCompareEnum(date, comparator,
max_date
ImportedTime: valuesToCompareEnum(formatDate(date)!!, comparator,
formatDate(max_date)
)
});
}

public static changedTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery {
return filterQuery({
ChangedTime: valuesToCompareEnum(date, comparator, max_date)
ChangedTime: valuesToCompareEnum(formatDate(date)!!, comparator, formatDate(max_date))
});
}

public static createdTime(date: Date, comparator: Comparator, max_date: Date): FilterQuery {
return filterQuery({
CreatedTime: valuesToCompareEnum(date, comparator, max_date)
CreatedTime: valuesToCompareEnum(formatDate(date)!!, comparator, formatDate(max_date))
});
}

Expand Down Expand Up @@ -150,6 +150,7 @@ export class FilterQueryBuilder {
}
break;
case "ImportedTime":
console.debug(propertyName, rawComparator, compareValue);
value = this.parsePropertyValue(compareValue, parseDate);
if (value != undefined) {
return this.importedTime(value[0], comparator, value[1]);
Expand Down Expand Up @@ -263,7 +264,7 @@ function filterQuery(propertyQuery: PropertyQuery): FilterQuery {
return { Property: propertyQuery };
}

function valuesToCompareEnum<T>(min_value: T, comparator: Comparator, max_value?: T): ValueComparator<T> {
function valuesToCompareEnum<T>(min_value: T, comparator: Comparator, max_value: T | undefined): ValueComparator<T> {
switch (comparator) {
case "Less":
return { Less: min_value };
Expand Down Expand Up @@ -299,9 +300,9 @@ function parseByteSize(value: string): number | undefined {
if (number) {
for (const key of Object.keys(valueMappings)) {
if (checkUnit(key)) {
console.log("key", key, "valueMapping", valueMappings[key]);
console.debug("key", key, "valueMapping", valueMappings[key]);
number *= valueMappings[key];
console.log("number", number);
console.debug("number", number);
break;
}
}
Expand All @@ -311,7 +312,7 @@ function parseByteSize(value: string): number | undefined {
}

function parseDate(value: string): Date | undefined {
const date = Date.parse(value);
const date = Date.parse(value.toUpperCase());

if (isNaN(date)) {
return undefined;
Expand All @@ -331,3 +332,13 @@ function parseStatus(value: string): FileStatus | undefined {
return undefined;
}
}

function formatDate(date?: Date): string | undefined {
if (date) {
const pad = (s: number) => s.toString().padStart(2, "0");
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
date.getMinutes())}:${pad(
date.getSeconds())}`;
}
return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class FileActionBaseComponent {
if (changeConfirmed) {
await this.errorBroker.try(async () => {
const newFile = await this.fileService.updateFileStatus(files[0].id, status);
files[0].status = newFile.status;
files[0].setStatus(newFile.getStatus());
});
}
} else {
Expand All @@ -72,7 +72,7 @@ export class FileActionBaseComponent {
files,
(file) => this.errorBroker.try(async () => {
const newFile = await this.fileService.updateFileStatus(file.id, status);
file.status = newFile.status;
file.setStatus(newFile.getStatus());
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<app-file-thumbnail
(loadEnd)="this.loading = false"
[class.hidden]="this.loading"
[fileChanged]="this.fileChanged"
[file]="this.entry.data"
class="entry-image"></app-file-thumbnail>
</app-busy-indicator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import {File} from "../../../../../api/models/File";
import {Selectable} from "../../../../models/Selectable";
import {SchedulingService} from "../../../../services/scheduling/scheduling.service";
import {BehaviorSubject} from "rxjs";

const LOADING_WORK_KEY = "FILE_THUMBNAIL_LOADING";

Expand All @@ -26,7 +25,6 @@ const LOADING_WORK_KEY = "FILE_THUMBNAIL_LOADING";
export class FileCardComponent implements OnInit, OnChanges, OnDestroy {

@Input() public entry!: Selectable<File>;
@Input() public fileChanged: BehaviorSubject<void> = new BehaviorSubject<void>(undefined);
@Output() clickEvent = new EventEmitter<FileCardComponent>();
@Output() dblClickEvent = new EventEmitter<FileCardComponent>();

Expand All @@ -47,9 +45,6 @@ export class FileCardComponent implements OnInit, OnChanges, OnDestroy {
this.cachedId = this.entry.data.id;
this.loading = true;
}
if (changes["fileChanged"]) {
this.fileChanged.subscribe(() => this.changeDetector.markForCheck());
}
}

public ngOnDestroy(): void {
Expand All @@ -62,19 +57,4 @@ export class FileCardComponent implements OnInit, OnChanges, OnDestroy {
console.debug(this.entry.data.id);
this.clickEvent.emit(this);
}

private setImageDelayed() {
if (this.workId) {
this.schedulingService.cancelWork(LOADING_WORK_KEY, this.workId);
}
this.loading = true;
this.workId = this.schedulingService.addWork(
LOADING_WORK_KEY,
async () => {
await this.schedulingService.delay(0);
this.loading = false;
this.changeDetector.markForCheck();
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export class FileContextMenuComponent extends FileActionBaseComponent implements
this.actionDelete = this.actionArchive = this.actionImported = this.actionRestore = false;

for (const file of this.files) {
this.actionDeletePermantently &&= file.status === "Deleted";
this.actionDelete ||= file.status !== "Deleted";
this.actionArchive ||= file.status !== "Archived" && file.status !== "Deleted";
this.actionImported ||= file.status !== "Imported" && file.status !== "Deleted";
this.actionRestore ||= file.status === "Deleted";
this.actionDeletePermantently &&= file.getStatus() === "Deleted";
this.actionDelete ||= file.getStatus() !== "Deleted";
this.actionArchive ||= file.getStatus() !== "Archived" && file.getStatus() !== "Deleted";
this.actionImported ||= file.getStatus() !== "Imported" && file.getStatus() !== "Deleted";
this.actionRestore ||= file.getStatus() === "Deleted";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
<div #previewStripContainer class="file-preview-strip-container">
<div *ngFor="let entry of this.previewedEntries; trackBy: trackByFileId" class="file-item">
<app-file-card (clickEvent)="onEntrySelect($event.entry)" *ngIf="entry"
[entry]="entry" [fileChanged]="this.fileChanged"></app-file-card>
[entry]="entry"></app-file-card>
</div>
</div>
</div>
</div>
<app-file-context-menu #fileContextMenu
(fileDeleted)="this.fileDeleted.emit($event)"
(fileStatusChange)="this.onFileStatusChange()"></app-file-context-menu>
(fileDeleted)="this.fileDeleted.emit($event)"></app-file-context-menu>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {SafeResourceUrl} from "@angular/platform-browser";
import {Selectable} from "../../../../../models/Selectable";
import {TabService} from "../../../../../services/tab/tab.service";
import {Key} from "w3c-keys";
import {BehaviorSubject} from "rxjs";

@Component({
selector: "app-file-gallery",
Expand All @@ -43,7 +42,6 @@ export class FileGalleryComponent implements OnChanges, OnInit, AfterViewInit, A
public entries: Selectable<File>[] = [];
public selectedFile: Selectable<File> | undefined;
public fileContentUrl: SafeResourceUrl | undefined;
public fileChanged = new BehaviorSubject<void>(undefined);

public selectedIndex = 0;
public imageViewHeightPercent = 80;
Expand Down Expand Up @@ -182,10 +180,6 @@ export class FileGalleryComponent implements OnChanges, OnInit, AfterViewInit, A
return item?.data.id;
}

public onFileStatusChange(): void {
this.fileChanged.next();
}

public togglePreviewStrip(): void {
if (this.previewStripVisible) {
this.imageViewHeightPercent = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(contextmenu)="this.selectEntryWhenNotSelected(gridEntry); fileContextMenu.onContextMenu($event, this.getSelectedFiles())"
(dblClickEvent)="fileOpen.emit($event.entry.data)"
*ngIf="gridEntry"
[entry]="gridEntry" [fileChanged]="this.fileChanged"></app-file-card>
[entry]="gridEntry"></app-file-card>
<div *ngIf="!gridEntry" class="empty-grid-entry"></div>
</ng-container>
</div>
Expand All @@ -23,8 +23,7 @@

</div>
<app-file-context-menu #fileContextMenu
(fileDeleted)="this.fileDeleted.emit($event)"
(fileStatusChange)="this.onFileStatusChange()">
(fileDeleted)="this.fileDeleted.emit($event)">
<button (click)="this.fileOpen.emit(fileContextMenu.files[0])"
*ngIf="fileContextMenu.files.length === 1"
content-before=""
Expand Down
Loading

0 comments on commit 351f74b

Please sign in to comment.