Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ildar-ceo opened this issue Nov 9, 2023 · 0 comments
Open

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

ildar-ceo opened this issue Nov 9, 2023 · 0 comments

Comments

@ildar-ceo
Copy link
Member

/**
 * 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();
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant