Skip to main content

plot/lib/schema/
job_ready.rs

1use std::path::PathBuf;
2
3use serde::Serialize;
4
5use super::{
6	SharedJobAttributeToSelect,
7	SharedJobOptForAttrItem,
8	SharedJobOptForAttrSize,
9	SharedJobPart,
10	SharedJobRunMode,
11	SharedJobStringMode,
12};
13
14// ░░░░░░░░░░░░░░░░░░░░ one【job】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
15
16#[derive(Debug, Clone, Serialize)]
17#[serde(rename_all = "kebab-case")]
18pub struct ReadyJob {
19	id: String,
20	description: String,
21	#[serde(rename = "run-mode")]
22	run_modes: Vec<SharedJobRunMode>,
23	explorer: ReadyJobExplorer,
24	export: ReadyJobExport,
25	attributes: ReadyJobAttributes,
26	tuples: ReadyJobTuples,
27}
28
29impl ReadyJob {
30	pub fn id(&self) -> &str { &self.id }
31	pub fn description(&self) -> &str { &self.description }
32	pub fn run_modes(&self) -> &[SharedJobRunMode] { &self.run_modes }
33	pub fn explorer(&self) -> &ReadyJobExplorer { &self.explorer }
34	pub fn export(&self) -> &ReadyJobExport { &self.export }
35	pub fn attributes(&self) -> &ReadyJobAttributes { &self.attributes }
36	pub fn tuples(&self) -> &ReadyJobTuples { &self.tuples }
37
38	// Konstruktor tylko dla warstwy mapującej
39	pub(crate) fn new(
40		id: String,
41		description: String,
42		run_modes: Vec<SharedJobRunMode>,
43		explorer: ReadyJobExplorer,
44		export: ReadyJobExport,
45		attributes: ReadyJobAttributes,
46		tuples: ReadyJobTuples,
47	) -> Self {
48		Self { id, description, run_modes, explorer, export, attributes, tuples }
49	}
50
51	/// Generuje sformatowaną reprezentację zadania w formacie TOML.
52	/// Metoda ta pozwala na łatwe "wstrzyknięcie" gotowego zadania z powrotem do pliku konfiguracyjnego.
53	pub fn insert_as_toml(&self) -> String {
54        // Tworzymy lokalną strukturę jednorazową specjalnie pod serializację
55        #[derive(serde::Serialize)]
56        struct TomlWrapper<'a> {
57            job: Vec<&'a ReadyJob>, 
58        }
59
60        let wrapper = TomlWrapper { job: vec![self] };
61
62        // Serializujemy owijkę. Serde samo wstawi [[job]] i [job.explorer]!
63        toml::to_string_pretty(&wrapper).unwrap_or_else(|_| format!("id = \"{}\"", self.id))
64    }
65}
66
67// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【explorer】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
68
69#[derive(Debug, Clone, Serialize)]
70#[serde(rename_all = "kebab-case")]
71pub struct ReadyJobExplorer {
72	workspace_dir: PathBuf,
73	ignore_case: bool,
74	patterns: Vec<String>,
75	parts: Vec<SharedJobPart>,
76}
77
78impl ReadyJobExplorer {
79	pub fn workspace_dir(&self) -> &PathBuf { &self.workspace_dir }
80	pub fn ignore_case(&self) -> bool { self.ignore_case }
81	pub fn patterns(&self) -> &[String] { &self.patterns }
82	pub fn parts(&self) -> &[SharedJobPart] { &self.parts }
83
84	pub(crate) fn new(
85		workspace_dir: PathBuf,
86		ignore_case: bool,
87		patterns: Vec<String>,
88		parts: Vec<SharedJobPart>,
89	) -> Self {
90		Self { workspace_dir, ignore_case, patterns, parts }
91	}
92}
93
94// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【export】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
95
96#[derive(Debug, Clone, Serialize)]
97#[serde(rename_all = "kebab-case")]
98pub struct ReadyJobExport {
99	out_dir: PathBuf,
100	title: String,
101	name: String,
102	name_is_first: bool,
103	save_separately: bool,
104}
105
106impl ReadyJobExport {
107	pub fn out_dir(&self) -> &PathBuf { &self.out_dir }
108	pub fn title(&self) -> &str { &self.title }
109	pub fn name(&self) -> &str { &self.name }
110	pub fn name_is_first(&self) -> bool { self.name_is_first }
111	pub fn save_separately(&self) -> bool { self.save_separately }
112
113	pub(crate) fn new(
114		out_dir: PathBuf,
115		title: String,
116		name: String,
117		name_is_first: bool,
118		save_separately: bool,
119	) -> Self {
120		Self { out_dir, title, name, name_is_first, save_separately }
121	}
122}
123
124// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【attributes】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
125
126#[derive(Debug, Clone, Serialize)]
127#[serde(rename_all = "kebab-case")]
128pub struct ReadyJobAttributes {
129	select: Vec<SharedJobAttributeToSelect>,
130	for_item: Vec<SharedJobOptForAttrItem>,
131	for_date: String,
132	for_time: String,
133	for_size: SharedJobOptForAttrSize,
134}
135
136impl ReadyJobAttributes {
137	pub fn select(&self) -> &[SharedJobAttributeToSelect] { &self.select }
138	pub fn for_item(&self) -> &[SharedJobOptForAttrItem] { &self.for_item }
139	pub fn for_date(&self) -> &str { &self.for_date }
140	pub fn for_time(&self) -> &str { &self.for_time }
141	pub fn for_size(&self) -> SharedJobOptForAttrSize { self.for_size }
142
143	pub(crate) fn new(
144		select: Vec<SharedJobAttributeToSelect>,
145		for_item: Vec<SharedJobOptForAttrItem>,
146		for_date: String,
147		for_time: String,
148		for_size: SharedJobOptForAttrSize,
149	) -> Self {
150		Self { select, for_item, for_date, for_time, for_size }
151	}
152}
153
154// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【tuples】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
155
156#[derive(Debug, Clone, Serialize)]
157#[serde(rename_all = "kebab-case")]
158pub struct ReadyJobTuples {
159	pile: ReadyJobTuplesPile,
160	sort: ReadyJobTuplesSort,
161}
162
163impl ReadyJobTuples {
164	pub fn pile(&self) -> &ReadyJobTuplesPile { &self.pile }
165	pub fn sort(&self) -> &ReadyJobTuplesSort { &self.sort }
166
167	pub(crate) fn new(pile: ReadyJobTuplesPile, sort: ReadyJobTuplesSort) -> Self { Self { pile, sort } }
168}
169
170// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【tuples】➔【pile】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
171
172#[derive(Debug, Clone, Serialize)]
173#[serde(tag = "type", rename_all = "kebab-case")]
174pub enum ReadyJobTuplesPile {
175	Name(ReadyJobPileMode),
176	Exte(ReadyJobPileMode),
177}
178
179// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【tuples】➔【pile】➔【mode】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
180
181#[derive(Debug, Clone, Serialize)]
182#[serde(rename_all = "kebab-case")]
183pub struct ReadyJobPileMode {
184	dir_first: bool,
185	same_name_dirs_and_files_nearby: bool,
186}
187
188impl ReadyJobPileMode {
189	pub fn dir_first(&self) -> bool { self.dir_first }
190	pub fn same_name_dirs_and_files_nearby(&self) -> bool { self.same_name_dirs_and_files_nearby }
191
192	pub(crate) fn new(dir_first: bool, same_name_dirs_and_files_nearby: bool) -> Self {
193		Self { dir_first, same_name_dirs_and_files_nearby }
194	}
195}
196
197// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【tuples】➔【sort】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
198
199#[derive(Debug, Clone, Serialize)]
200#[serde(tag = "type", rename_all = "kebab-case")]
201pub enum ReadyJobTuplesSort {
202	Path(ReadyJobSortTex),
203	Name(ReadyJobSortTex),
204	Date(ReadyJobSortNum),
205	Size(ReadyJobSortNum),
206}
207
208// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【tuples】➔【sort】➔【num】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
209
210#[derive(Debug, Clone, Serialize)]
211#[serde(rename_all = "kebab-case")]
212pub struct ReadyJobSortNum {
213	reverse: bool,
214}
215
216impl ReadyJobSortNum {
217	pub fn reverse(&self) -> bool { self.reverse }
218
219	pub(crate) fn new(reverse: bool) -> Self { Self { reverse } }
220}
221
222// ░░░░░░░░░░░░░░░░░░░░ 【job】➔【tuples】➔【sort】➔【tex】 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
223
224#[derive(Debug, Clone, Serialize)]
225#[serde(rename_all = "kebab-case")]
226pub struct ReadyJobSortTex {
227	reverse: bool,
228	mirror: bool,
229	string_strategy: Vec<SharedJobStringMode>,
230}
231
232impl ReadyJobSortTex {
233	pub fn reverse(&self) -> bool { self.reverse }
234	pub fn mirror(&self) -> bool { self.mirror }
235	pub fn string_strategy(&self) -> &[SharedJobStringMode] { &self.string_strategy }
236
237	pub(crate) fn new(reverse: bool, mirror: bool, string_strategy: Vec<SharedJobStringMode>) -> Self {
238		Self { reverse, mirror, string_strategy }
239	}
240}
241
242// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
243// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
244// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░