···11-use dto::{NanoId, TagModel, TagModelEx};
11+use color_eyre::eyre::Result;
22+use dto::{IntoActiveModel as _, NanoId, TagEntity, TagModel, TagModelEx, ZettelEntity};
2333-use crate::types::Color;
44+use crate::types::{Color, Kasten, Zettel};
4556/// Represents a `Tag` in a `ZettelKasten` note taking method.
67/// Easy way to link multiple notes under one simple word.
···1516 pub name: String,
1617 /// Color of the tag
1718 pub color: Color,
1919+}
2020+2121+impl Tag {
2222+ pub async fn alter_name(
2323+ id: NanoId,
2424+ new_name: impl Into<String>,
2525+ kt: &mut Kasten,
2626+ ) -> Result<()> {
2727+ let new_name = new_name.into();
2828+2929+ TagEntity::load()
3030+ .filter_by_nano_id(id.clone())
3131+ .one(&kt.db)
3232+ .await?
3333+ .expect("Invariant Broken: Must exist")
3434+ .into_active_model()
3535+ .set_name(new_name.as_str())
3636+ .update(&kt.db)
3737+ .await?;
3838+3939+ // fetch all the zettels for this tag
4040+ let tag = TagEntity::load()
4141+ .filter_by_nano_id(id)
4242+ .with(ZettelEntity)
4343+ .one(&kt.db)
4444+ .await?
4545+ .expect("We just saved it");
4646+4747+ assert!(
4848+ tag.zettels.is_loaded(),
4949+ "We expect the zettels to be loaded"
5050+ );
5151+5252+ for zettel in tag.zettels {
5353+ Zettel::write_tags_from_db(zettel.nano_id.into(), kt).await?;
5454+ }
5555+5656+ Ok(())
5757+ }
1858}
19592060impl From<TagModel> for Tag {
+12
src/types/zettel/mod.rs
···7575 Ok(())
7676 }
77777878+ /// Gets the tags from the database for this `Zettel` and write it to the file.
7979+ pub async fn write_tags_from_db(id: ZettelId, kt: &mut Kasten) -> Result<()> {
8080+ let zettel = Self::fetch_from_db(&id, &kt.db).await?.expect("must exist");
8181+8282+ let file_path = zettel.absolute_path(&kt.index);
8383+ let new_fm = FrontMatter::from(zettel);
8484+8585+ new_fm.flush_to_file(file_path)?;
8686+ kt.index.process_zid(&id)?;
8787+ Ok(())
8888+ }
8989+7890 pub async fn new(title: impl Into<String>, kt: &mut Kasten, tags: Vec<Tag>) -> Result<Self> {
7991 // fn new(title: impl Into<String>) -> Result<Self> {
8092 let title = title.into();
+7
src/viz/mod.rs
···104104 self.filaments.set_links_for_zid(&zid, links);
105105 }
106106107107+ // this will refresh the entire screen, esentially spawning
108108+ // in a new graph, maybe there is a better way to do this?
109109+ // might be clean with conditional name-showing...
110110+ Signal::Refresh => block_on(async {
111111+ let index = &self.kh.read().await.index;
112112+ self.filaments = Filaments::from(index);
113113+ }),
107114 _ => {}
108115 }
109116 }