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

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

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

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

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { invoke } from '@tauri-apps/api'; 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'; import { Plan, PlanInterface } from '../_models/plan';
@Injectable({ @Injectable({
@ -10,9 +10,14 @@ export class PlanService {
currentPlan?: Plan; currentPlan?: Plan;
planStore: string[] = []; planStore: string[] = [];
basePlan?: Plan;
private basePlanSubj: Subject<Plan> = new ReplaySubject<Plan>(1);
constructor() { constructor() {
this.getPreviousPlans(); this.getPreviousPlans();
this.loadBasePlan();
} }
loadPlan(path: string) { loadPlan(path: string) {
@ -34,8 +39,18 @@ export class PlanService {
); );
} }
loadBasePlan() { 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) { savePlan(path: string, plan: Plan) {
@ -64,4 +79,12 @@ export class PlanService {
this.currentPlan.setPrevious(name); 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 { return {
area_key: area.named_id, area_key: area.named_id,
notes: undefined, notes: undefined,
uuid: undefined,
edited: false
}; };
} }
@ -254,6 +256,7 @@ export class EditorComponent implements OnInit {
dialogRef.afterClosed().subscribe(note => { dialogRef.afterClosed().subscribe(note => {
if(note) { if(note) {
item.notes = note; item.notes = note;
item.edited = true;
} }
}) })

Loading…
Cancel
Save