pub struct App { /* private fields */ }Expand description
An application from its records: the module with the actions every application needs, the screens, and records in memory unless told otherwise.
use ravenrs_app::{BusinessObject, ObjectSpaceExt};
use ravenrs_app_ui::{App, Language};
#[derive(BusinessObject)]
#[object(caption = "Contas", navigation = "Cadastros")]
struct Account {
#[field(key)]
id: i64,
#[field(caption = "Nome")]
name: String,
}
let window = App::new("Raven Contas")
.language(Language::BrazilianPortuguese)
.entity::<Account>()
.seed(|space| {
space.add(&Account { id: 0, name: "Carteira".into() }).map_err(|e| e.to_string())
})
.build()?;Implementations§
Source§impl App
impl App
Sourcepub fn new(title: impl Into<String>) -> Self
pub fn new(title: impl Into<String>) -> Self
An application with this title, and nothing in it yet.
Sourcepub fn administrator_settings(self, difference: impl Into<String>) -> Self
pub fn administrator_settings(self, difference: impl Into<String>) -> Self
What the administrator of an installation set in the model, as a difference in JSON. Fields it adds to an entity reach storage too.
Sourcepub fn records_of(
self,
entity: impl Into<String>,
source: impl Fn() -> Vec<Object> + 'static,
) -> Self
pub fn records_of( self, entity: impl Into<String>, source: impl Fn() -> Vec<Object> + 'static, ) -> Self
The records of an entity no storage keeps, for its list and its forms.
Sourcepub fn collection_of(
self,
entity: impl Into<String>,
field: impl Into<String>,
source: impl Fn(&Object) -> Vec<Object> + 'static,
) -> Self
pub fn collection_of( self, entity: impl Into<String>, field: impl Into<String>, source: impl Fn(&Object) -> Vec<Object> + 'static, ) -> Self
The records of a list no storage keeps, inside a form of this entity.
Sourcepub fn texts(self, language: impl Into<String>, json: impl Into<String>) -> Self
pub fn texts(self, language: impl Into<String>, json: impl Into<String>) -> Self
Adds or replaces words of its screens, and of any component in them, as a flat JSON of keys
in the language of this code: { "ui.save": "Gravar" }. The keys that come with it are in
ravenrs-app-i18n; keys of its own, for its modules, go here too, and screens read them with
Session::texts. Given more than once, the last one wins.
Sourcepub fn entity<T: BusinessObject>(self) -> Self
pub fn entity<T: BusinessObject>(self) -> Self
Adds a record declared as a struct.
Sourcepub fn entity_info(self, entity: EntityInfo) -> Self
pub fn entity_info(self, entity: EntityInfo) -> Self
Adds a record declared at run time.
Sourcepub fn action(self, make: impl Fn() -> Action + 'static) -> Self
pub fn action(self, make: impl Fn() -> Action + 'static) -> Self
Adds an action of its own, with no module to write. It is made again for each window, so each one turns it on and off by itself; its target entity or view says where it shows.
use ravenrs_app::{Action, BusinessObject, Selection};
use ravenrs_app_ui::App;
#[derive(BusinessObject)]
struct Bill {
#[field(key)]
id: i64,
paid: bool,
}
let app = App::new("Contas").entity::<Bill>().action(|| {
Action::background("Pay", "Pagar", |job| {
for bill in job.selected() {
let mut bill = bill.clone();
bill.set("paid", true);
job.save(bill);
}
Ok(())
})
.target_entity("Bill")
.selection(Selection::RequireMultiple)
});Sourcepub fn module(self, module: impl Module + 'static) -> Self
pub fn module(self, module: impl Module + 'static) -> Self
Adds a module of its own, over the one with the actions every application needs.
Sourcepub fn editors(self, editors: EditorRegistry) -> Self
pub fn editors(self, editors: EditorRegistry) -> Self
Controls of its own for fields.
Sourcepub fn translation(
self,
language: impl Into<String>,
difference: impl Into<String>,
) -> Self
pub fn translation( self, language: impl Into<String>, difference: impl Into<String>, ) -> Self
Sourcepub fn service<T: 'static>(self, service: T) -> Self
pub fn service<T: 'static>(self, service: T) -> Self
Gives actions and controllers something the application has.
Sourcepub fn dashboard(self, dashboard: DashboardInfo) -> Self
pub fn dashboard(self, dashboard: DashboardInfo) -> Self
Adds a view of other views together.
Sourcepub fn list_editor(
self,
name: impl Into<String>,
editor: impl Fn(&ListEditorRequest) -> AnyView + 'static,
) -> Self
pub fn list_editor( self, name: impl Into<String>, editor: impl Fn(&ListEditorRequest) -> AnyView + 'static, ) -> Self
A way to show a list, for the model to pick by name.
Sourcepub fn attachment_store(self, store: impl AttachmentStore + 'static) -> Self
pub fn attachment_store(self, store: impl AttachmentStore + 'static) -> Self
Keeps the content of attached files there, apart from the records.
Sourcepub fn model_store(self, store: impl ModelStore + 'static) -> Self
pub fn model_store(self, store: impl ModelStore + 'static) -> Self
Keeps the person’s own settings there.
Sourcepub fn seed(
self,
seed: impl FnOnce(&mut dyn ObjectSpace) -> Result<(), String> + 'static,
) -> Self
pub fn seed( self, seed: impl FnOnce(&mut dyn ObjectSpace) -> Result<(), String> + 'static, ) -> Self
What is in its records when it opens, kept with a commit once this is done.
Sourcepub fn keep_in(self, storage: impl Storage + 'static) -> Self
pub fn keep_in(self, storage: impl Storage + 'static) -> Self
Keeps the records and the person’s own settings in storage between runs: a
FileStorage folder on the desktop, the browser’s IndexedDB
on the web. The records stay in memory while the app runs and are written after every
commit, under records; the settings go under settings. The seed runs
only the first time, while nothing was kept yet.
Sourcepub fn storage<S: ObjectSpace + 'static>(
self,
space: impl Fn() -> S + 'static,
) -> Self
pub fn storage<S: ObjectSpace + 'static>( self, space: impl Fn() -> S + 'static, ) -> Self
Keeps records elsewhere than in memory: this makes the unit of work of each view.
Sourcepub fn storage_for<S, F>(
self,
make: impl FnOnce(&[EntityInfo]) -> F + 'static,
) -> Selfwhere
S: ObjectSpace + 'static,
F: Fn() -> S + 'static,
pub fn storage_for<S, F>(
self,
make: impl FnOnce(&[EntityInfo]) -> F + 'static,
) -> Selfwhere
S: ObjectSpace + 'static,
F: Fn() -> S + 'static,
Keeps records elsewhere than in memory, in something made from the entities as the model has them, with the fields its layers added: this makes what makes the unit of work of each view.
Sourcepub fn with_session(self, then: impl FnOnce(&Session) + 'static) -> Self
pub fn with_session(self, then: impl FnOnce(&Session) + 'static) -> Self
Runs this with its session, once it is put together, for what needs a session from outside.
Sourcepub fn build(self) -> Result<AnyView, ModelError>
pub fn build(self) -> Result<AnyView, ModelError>
Puts it together, or says what is wrong with how it was declared.