bayrell-os / cloud_os_standard

BAYRELL Cloud OS (Open Source Cloud Platform)
https://cloud.bayrell.org/
Apache License 2.0
7 stars 1 forks source link

Рефакторинг AppApi #127

Open ildar-ceo opened 1 year ago

ildar-ceo commented 1 year ago
/**
 * Set item variables
 */
void setItemVariables(Dict update_data)
{
    /* Get item variables */
    Map<string> item_variables = this.item.get("variables");
    if (item_variables == null) item_variables = new Map;

    /* Save variables */
    Vector variables = update_data["variables"];
    if (variables)
    {
        for (int i=0; i<variables.count(); i++)
        {
            Map variable = variables.get(i);
            item_variables.setValue(
                variable.get("name"),
                variable.get("value")
            );
        }
    }

    /* Set variables */
    item.set("variables", item_variables);
}

/**
 * Create app xml object
 */
void createAppXMLObject()
{
    if (this.xml == null)
    {
        this.xml = new AppXml(this.item);
        this.xml.conn = this.getDatabaseConnection();
    }
}

/**
 * Before update item event
 */
async void onSaveAfter(Dict update_data)
{
    await parent::onSaveAfter(update_data);

    /* Set variables */
    this.setItemVariables(update_data)

    /* Create AppXml */
    this.createAppXMLObject();

    /* Build xml and yaml content */
    Dict pk = this.post_data["pk"];
    await this.xml.buildContent(pk == null);

    /* Set xml content */
    item.set("content", this.xml.xml_content);
    item.set("yaml", this.xml.yaml_content);
    await item.save(xml.conn);
}

/**
 * Search final
 */
async void onSearchFinal()
{
    await parent::onSearchFinal();

    if (this.action == "actionItem")
    {
        this.createAppXMLObject();
        await this.xml.buildContent();
    }
}