Skip to main content

App

Struct App 

Source
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

Source

pub fn new(title: impl Into<String>) -> Self

An application with this title, and nothing in it yet.

Source

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.

Source

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.

Source

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.

Source

pub fn language(self, language: Language) -> Self

The language of its screens.

Source

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.

Source

pub fn entity<T: BusinessObject>(self) -> Self

Adds a record declared as a struct.

Source

pub fn entity_info(self, entity: EntityInfo) -> Self

Adds a record declared at run time.

Source

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)
});
Source

pub fn module(self, module: impl Module + 'static) -> Self

Adds a module of its own, over the one with the actions every application needs.

Source

pub fn editors(self, editors: EditorRegistry) -> Self

Controls of its own for fields.

Source

pub fn translation( self, language: impl Into<String>, difference: impl Into<String>, ) -> Self

The model in another language, as a difference in JSON. The one for its language, en or pt-BR, is the one used. Words of the screens, not of the model, go to texts.

Source

pub fn service<T: 'static>(self, service: T) -> Self

Gives actions and controllers something the application has.

Source

pub fn dashboard(self, dashboard: DashboardInfo) -> Self

Adds a view of other views together.

Source

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.

Source

pub fn attachment_store(self, store: impl AttachmentStore + 'static) -> Self

Keeps the content of attached files there, apart from the records.

Source

pub fn model_store(self, store: impl ModelStore + 'static) -> Self

Keeps the person’s own settings there.

Source

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.

Source

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.

Source

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.

Source

pub fn storage_for<S, F>( self, make: impl FnOnce(&[EntityInfo]) -> F + 'static, ) -> Self
where 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.

Source

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.

Source

pub fn build(self) -> Result<AnyView, ModelError>

Puts it together, or says what is wrong with how it was declared.

Source

pub fn into_view(self) -> AnyView

Puts it together, showing on the screen what is wrong with how it was declared.

Trait Implementations§

Source§

impl Debug for App

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl !UnwindSafe for App

§

impl Freeze for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more