plan element identifiers, allows finding diffs on specific elements for merging in base plan changes into your own plan

merge-notes
isark 2 years ago
parent 1c84c43ceb
commit c1354236c7

@ -1978,6 +1978,7 @@ dependencies = [
"tauri",
"tauri-build",
"ts-rs",
"uuid",
"x11rb",
]
@ -3880,11 +3881,12 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "uuid"
version = "1.4.1"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560"
dependencies = [
"getrandom 0.2.10",
"serde",
]
[[package]]

@ -38,6 +38,7 @@ directories = "5.0.1"
notify = "6.0.1"
regex = "1.9.3"
lazy_static = "1.4.0"
uuid = { version = "1.6.1", features = ["v4", "serde"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem

@ -18,6 +18,22 @@ impl Plan {
pub struct PlanElement {
area_key: String,
notes: String,
#[serde(default = "PlanElement::generate_uuid")]
uuid: uuid::Uuid,
#[serde(default = "PlanElement::edited")]
edited: bool,
}
impl PlanElement {
pub fn generate_uuid() -> uuid::Uuid {
uuid::Uuid::new_v4()
}
pub fn edited() -> bool {
false
}
}
#[derive(Debug, Deserialize)]
@ -58,6 +74,8 @@ pub fn convert_old(path: &str) -> Option<Plan> {
.map(|plan_element| PlanElement {
area_key: map[&plan_element.area._rid].to_owned(),
notes: plan_element.note,
uuid: PlanElement::generate_uuid(),
edited: PlanElement::edited(),
})
.collect::<Vec<PlanElement>>(),
stored_path: None

@ -68,4 +68,6 @@ export class Plan {
export interface PlanElement {
area_key: string;
notes?: string;
uuid?: string;
edited: boolean;
}

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { invoke } from '@tauri-apps/api';
import { from, map, tap } from 'rxjs';
import { Observable, ReplaySubject, Subject, from, map, tap } from 'rxjs';
import { Plan, PlanInterface } from '../_models/plan';
@Injectable({
@ -10,9 +10,14 @@ export class PlanService {
currentPlan?: Plan;
planStore: string[] = [];
basePlan?: Plan;
private basePlanSubj: Subject<Plan> = new ReplaySubject<Plan>(1);
constructor() {
this.getPreviousPlans();
this.loadBasePlan();
}
loadPlan(path: string) {
@ -34,8 +39,18 @@ export class PlanService {
);
}
loadBasePlan() {
return from(invoke<PlanInterface>('base_plan'));
if(!this.basePlan) {
from(invoke<PlanInterface>('base_plan')).subscribe(plan => {
plan.plan.forEach(elem => {elem.edited = false;});
this.basePlan = new Plan(plan);
this.basePlanSubj?.next(this.basePlan);
});
}
return this.basePlanSubj!.asObservable();
}
savePlan(path: string, plan: Plan) {
@ -64,4 +79,12 @@ export class PlanService {
this.currentPlan.setPrevious(name);
}));
}
zoneFromUuid(uuid: string) {
if (!this.basePlan) {
return undefined;
}
return this.basePlan.plan.find(elem => elem.uuid === uuid);
}
}

@ -143,6 +143,8 @@ export class EditorComponent implements OnInit {
return {
area_key: area.named_id,
notes: undefined,
uuid: undefined,
edited: false
};
}
@ -254,6 +256,7 @@ export class EditorComponent implements OnInit {
dialogRef.afterClosed().subscribe(note => {
if(note) {
item.notes = note;
item.edited = true;
}
})

Loading…
Cancel
Save