Skip to content

Commit

Permalink
Merge branch 'main' into spring-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacornelius committed Mar 1, 2024
2 parents 3a2f56e + 6eab3b7 commit e97b7b7
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/generate_index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Generate Index

on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches:
- "**"
pull_request:
types: [opened, reopened, synchronize, edited]

jobs:
build:
name: "Generate index and readme"
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: ${{github.head_ref}}

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Check committer
id: check
run: |
COMMITTER=$(git log -1 --pretty=format:'%ae')
echo "COMMITTER=$COMMITTER" >> $GITHUB_ENV
- name: Run script
run: php .github/workflows/scripts/generate_index.php
if: env.COMMITTER != 'action@github.com'

- name: Commit and push if it changed
run: |
git diff
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "Update index.json and README.md" || exit 0
git push
203 changes: 203 additions & 0 deletions .github/workflows/scripts/generate_index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

function compute_hash($data) {
return $data ? sha1($data) : null;
}

function update_readme($categories) {
$readme = fopen("README.md", "w");
fwrite($readme,
"# Screen Templates\nEnhance the usability and functionality of ProcessMaker. These templates offer offer features for selecting, saving, and designating default templates, ultimately streamlining the workflow."
);
ksort($categories); // Sort categories alphabetically
foreach ($categories as $category => $templates) {
$category = str_replace("-", " ", $category);
$category = ucwords($category);
fwrite($readme, "\n## $category\n");
// Sort templates alphabetically within each category
usort($templates, function($a, $b) { return strcmp($a['name'], $b['name']); });

foreach ($templates as $template) {
foreach ($template as $value) {
$string = "- **[{$value['name']}](/{$value['relative_path']})**: {$value['description']}";
if ($value['version']) {
$string .= " (Version {$value['version']})\n";
} else {
$string .= "\n";
}
fwrite($readme, $string);
}

}
}
fclose($readme);
}

function main()
{
$rootDirectory = ".";
$categories = [];

// Iterate over category directories
foreach (new DirectoryIterator($rootDirectory) as $categoryInfo) {
if ($categoryInfo->isDot() || strpos($categoryInfo->getBasename(), ".") === 0) {
continue;
}

if ($categoryInfo->isDir()) {
$currentCategory = $categoryInfo->getFilename();

if (!isset($categories[$currentCategory])) {
$categories[$currentCategory] = [];
}

// Iterate over template directories within each category
foreach (new DirectoryIterator($categoryInfo->getPathname()) as $templateInfo) {
if ($templateInfo->isDot() || strpos($templateInfo->getBasename(), ".") === 0) {
continue;
}

if ($templateInfo->isDir()) {
$templateName = $templateInfo->getFilename();
$categories[$currentCategory][$templateName] = initializeTemplateStructure();

// Iterate over template contents
foreach (new DirectoryIterator($templateInfo->getPathname()) as $contentInfo) {
if ($contentInfo->isDot() || strpos($templateInfo->getBasename(), ".") === 0) {
continue;
}

handleTemplateContent($contentInfo, $categories, $currentCategory, $templateName);
}
}
}
}
}

file_put_contents("index.json", json_encode($categories, JSON_PRETTY_PRINT));
}

function initializeTemplateStructure()
{
return [
"screen" => "",
"template_details" => [
"name" => "",
"description" => "",
"screen_type" => "",
'version' => "",
],
"assets" => [
"thumbnail" => "",
"preview-thumbs" => []
],
];
}

function handleTemplateContent($contentInfo, &$categories, $currentCategory, $templateName)
{
if ($contentInfo->isDir()) {
handleAssetDirectory($contentInfo, $categories, $currentCategory, $templateName);
} else {
mapContentToTemplateStructure($contentInfo, $categories, $currentCategory, $templateName);
}
}

function handleAssetDirectory($assetDirectory, &$categories, $currentCategory, $templateName)
{
$assets = new DirectoryIterator($assetDirectory->getPathname());

foreach ($assets as $assetFileInfo) {
if ($assetFileInfo->isDot() || strpos($assetFileInfo->getBasename(), '.') === 0) {
continue;
}

handleAssetFile($assetFileInfo, $categories, $currentCategory, $templateName);
}
}

function handleAssetFile($assetFileInfo, &$categories, $currentCategory, $templateName)
{
$assetName = $assetFileInfo->getFilename();
$assetName = substr($assetName, 0, strrpos($assetName, "."));

if ($assetName === 'thumbnail') {
$categories[$currentCategory][$templateName]['assets']['thumbnail'] = $assetFileInfo->getPathname();
}

if ($assetFileInfo->isDir()) {
handleSubDirectoryAssets($assetFileInfo, $categories, $currentCategory, $templateName);
}
}

function handleSubDirectoryAssets($directory, &$categories, $currentCategory, $templateName)
{
$path = explode('/', $directory->getPathname());
$directoryName = end($path);
$parentName = prev($path);

foreach (new DirectoryIterator($directory->getPathname()) as $fileInfo) {
if ($fileInfo->isDot() || strpos($fileInfo->getBasename(), '.') === 0) {
continue;
}

if ($fileInfo->isDir()) {
handleSubDirectoryAssets($fileInfo, $categories, $currentCategory, $templateName);
} else {
handleAssetSubDirectoryFile($fileInfo, $categories, $currentCategory, $templateName, $parentName, $directoryName);
}
}
}

function handleAssetSubDirectoryFile($fileInfo, &$categories, $currentCategory, $templateName, $parentName, $directoryName)
{
$assetName = $fileInfo->getFilename();
$assetName = substr($assetName, 0, strrpos($assetName, "."));

array_push($categories[$currentCategory][$templateName][$parentName][$directoryName], $fileInfo->getPathname());
}

function mapContentToTemplateStructure($contentInfo, &$categories, $currentCategory, $templateName)
{
$fileName = $contentInfo->getFilename();
$fileName = substr($fileName, 0, strrpos($fileName, "."));

switch ($fileName) {
case "screen_export":
$categories[$currentCategory][$templateName]['screen'] = $contentInfo->getPathname();
break;
case "screen-template-details":
loadXmlAttributes($contentInfo, $categories, $currentCategory, $templateName);
break;
}
}

function loadXmlAttributes($contentInfo, &$categories, $currentCategory, $templateName)
{
$xml = simplexml_load_file($contentInfo->getPathname());

$name = (string) $xml->attributes()['name'];
$description = (string) $xml->attributes()['description'];
$screenType = (string) $xml->attributes()['screen_type'];
$version = (string) $xml->attributes()['version'];


$categories[$currentCategory][$templateName]['template_details']['name'] = $name;
$categories[$currentCategory][$templateName]['template_details']['description'] = $description;
$categories[$currentCategory][$templateName]['template_details']['screen_type'] = $screenType;
$categories[$currentCategory][$templateName]['template_details']['version'] = $version;
}

// You also need to define the compute_hash and update_readme functions if they are not already defined.

function sort_categories(&$categories) {
ksort($categories);
foreach ($categories as &$category) {
if (is_array($category)) {
sort_categories($category);
}
}
}


main();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Accounting/Business Expense/assets/thumbnail.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Accounting/Business Expense/screen-template-details.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<screen-template
name="Test Screen Template"
description="Approve and Reject invoice using OCR"
screen_type="FORM"
version="1.0.0"
></screen-template>
1 change: 1 addition & 0 deletions Accounting/Business Expense/screen_export.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"screen_package","version":"2","screens":[{"id":32,"uuid":"9b76258f-a64b-4509-bf4a-5c03bd7b143d","screen_category_id":"1","title":"Test Screen","description":"Test","type":"FORM","config":[{"name":"Test Screen","items":[{"label":"Line Input","config":{"icon":"far fa-square","name":"form_input_1","type":"text","label":"New Input","helper":null,"dataFormat":"string","validation":null,"placeholder":null},"component":"FormInput","inspector":[{"type":"FormInput","field":"name","config":{"name":"Variable Name","label":"Variable Name","helper":"A variable name is a symbolic name to reference information.","validation":"regex:\/^([a-zA-Z]([a-zA-Z0-9_]?)+\\.?)+(?<!\\.)$\/|required|not_in:null,break,case,catch,continue,debugger,default,delete,do,else,finally,for,function,if,in,instanceof,new,return,switch,this,throw,try,typeof,var,void,while,with,class,const,enum,export,extends,import,super,true,false"}},{"type":"FormInput","field":"label","config":{"label":"Label","helper":"The label describes the field's name"}},{"type":"FormMultiselect","field":"dataFormat","config":{"name":"Data Type","label":"Data Type","helper":"The data type specifies what kind of data is stored in the variable.","options":[{"value":"string","content":"Text"},{"value":"int","content":"Integer"},{"value":"currency","content":"Currency"},{"value":"percentage","content":"Percentage"},{"value":"float","content":"Decimal"},{"value":"datetime","content":"Datetime"},{"value":"date","content":"Date"},{"value":"password","content":"Password"}],"validation":"required"}},{"type":{"extends":{"props":["label","error","options","helper","name","value","selectedControl"],"mixins":[{"name":"ValidationMixin","props":{"config":{"type":null},"validation":{"type":null},"validationData":{"type":null},"validationField":{"type":null},"validationMessages":{"type":null}},"watch":{"validationData":{"deep":true}},"mixins":[{"name":"ProxyDataMixin","methods":[]}],"methods":[],"computed":[]}],"methods":[],"computed":[],"_compiled":true,"components":{"RequiredAsterisk":{"name":"RequiredAsterisk","_Ctor":[],"_compiled":true,"staticRenderFns":[]}},"inheritAttrs":false,"staticRenderFns":[]},"computed":[],"_compiled":true,"staticRenderFns":[]},"field":"dataMask","config":{"name":"Data Format","label":"Data Format","helper":"The data format for the selected type."}},{"type":"ValidationSelect","field":"validation","config":{"label":"Validation Rules","helper":"The validation rules needed for this field"}},{"type":"FormInput","field":"placeholder","config":{"label":"Placeholder Text","helper":"The placeholder is what is shown in the field when no value is provided yet"}},{"type":"FormInput","field":"helper","config":{"label":"Helper Text","helper":"Help text is meant to provide additional guidance on the field's value"}},{"type":"FormCheckbox","field":"readonly","config":{"label":"Read Only"}},{"type":"ColorSelect","field":"color","config":{"label":"Text Color","helper":"Set the element's text color","options":[{"value":"text-primary","content":"primary"},{"value":"text-secondary","content":"secondary"},{"value":"text-success","content":"success"},{"value":"text-danger","content":"danger"},{"value":"text-warning","content":"warning"},{"value":"text-info","content":"info"},{"value":"text-light","content":"light"},{"value":"text-dark","content":"dark"}]}},{"type":"ColorSelect","field":"bgcolor","config":{"label":"Background Color","helper":"Set the element's background color","options":[{"value":"alert alert-primary","content":"primary"},{"value":"alert alert-secondary","content":"secondary"},{"value":"alert alert-success","content":"success"},{"value":"alert alert-danger","content":"danger"},{"value":"alert alert-warning","content":"warning"},{"value":"alert alert-info","content":"info"},{"value":"alert alert-light","content":"light"},{"value":"alert alert-dark","content":"dark"}]}},{"type":"default-value-editor","field":"defaultValue","config":{"label":"Default Value","helper":"The default value is pre populated using the existing request data. This feature will allow you to modify the value displayed on screen load if needed."}},{"type":"FormInput","field":"conditionalHide","config":{"label":"Visibility Rule","helper":"This control is hidden until this expression is true"}},{"type":"DeviceVisibility","field":"deviceVisibility","config":{"label":"Device Visibility","helper":"This control is hidden until this expression is true"}},{"type":"FormInput","field":"customFormatter","config":{"label":"Custom Format String","helper":"Use the Mask Pattern format <br> Date ##\/##\/#### <br> SSN ###-##-#### <br> Phone (###) ###-####","validation":null}},{"type":"FormInput","field":"customCssSelector","config":{"label":"CSS Selector Name","helper":"Use this in your custom css rules","validation":"regex: [-?[_a-zA-Z]+[_-a-zA-Z0-9]*]"}},{"type":"FormInput","field":"ariaLabel","config":{"label":"Aria Label","helper":"Attribute designed to help assistive technology (e.g. screen readers) attach a label"}},{"type":"FormInput","field":"tabindex","config":{"label":"Tab Order","helper":"Order in which a user will move focus from one control to another by pressing the Tab key","validation":"regex: [0-9]*"}}],"editor-control":"FormInput","editor-component":"FormInput"},{"label":"Submit Button","config":{"icon":"fas fa-share-square","name":null,"event":"submit","label":"New Submit","loading":false,"tooltip":[],"variant":"primary","fieldValue":null,"loadingLabel":"Loading...","defaultSubmit":true},"component":"FormButton","inspector":[{"type":"FormInput","field":"label","config":{"label":"Label","helper":"The label describes the button's text"}},{"type":"FormInput","field":"name","config":{"name":"Variable Name","label":"Variable Name","helper":"A variable name is a symbolic name to reference information.","validation":"regex:\/^(?:[A-Za-z])(?:[0-9A-Z_.a-z])*(?<![.])$\/|not_in:null,break,case,catch,continue,debugger,default,delete,do,else,finally,for,function,if,in,instanceof,new,return,switch,this,throw,try,typeof,var,void,while,with,class,const,enum,export,extends,import,super,true,false"}},{"type":"FormMultiselect","field":"event","config":{"label":"Type","helper":"Choose whether the button should submit the form","options":[{"value":"submit","content":"Submit Button"},{"value":"script","content":"Regular Button"}]}},{"type":"LoadingSubmitButton","field":"loading","config":{"label":"Loading Submit Button","helper":"Loading Submit Button"}},{"type":"LabelSubmitButton","field":"loadingLabel","config":{"label":"Loading Submit Button Label","helper":"Loading Submit Button Label"}},{"type":{"props":["label","value","helper"],"watch":{"value":{"immediate":true}},"methods":[],"computed":[],"_compiled":true,"components":{"FormTextArea":{"name":"FormTextArea","_Ctor":[],"props":{"name":{"type":null},"rows":{"type":null},"error":{"type":null},"label":{"type":null},"value":{"type":null},"helper":{"type":null},"readonly":{"type":null},"richtext":{"type":null},"controlClass":{"type":null}},"watch":{"rows":{"immediate":true}},"mixins":[{"methods":[],"directives":{"uni-id":[],"uni-for":[],"uni-form":[],"uni-aria-owns":[],"uni-aria-flowto":[],"uni-aria-controls":[],"uni-aria-labelledby":[],"uni-aria-describedby":[],"uni-aria-activedescendant":[]}},{"name":"ValidationMixin","props":{"config":{"type":null},"validation":{"type":null},"validationData":{"type":null},"validationField":{"type":null},"validationMessages":{"type":null}},"watch":{"validationData":{"deep":true,"user":true}},"mixins":[{"name":"ProxyDataMixin","methods":[]}],"methods":[],"computed":[]}],"methods":[],"computed":[],"_compiled":true,"components":{"Editor":{"props":{"plugins":[null,null],"toolbar":[null,null],"modelEvents":[null,null]},"watch":[]},"DisplayErrors":{"props":["name","error","validator"],"computed":[],"_compiled":true,"staticRenderFns":[]},"RequiredAsterisk":{"name":"RequiredAsterisk","_Ctor":[],"_compiled":true,"staticRenderFns":[]}},"inheritAttrs":false,"staticRenderFns":[]}},"inheritAttrs":false,"staticRenderFns":[]},"field":"tooltip","config":{"label":"Tooltip"}},{"type":"FormInput","field":"fieldValue","config":{"label":"Value","helper":"The value being submitted"}},{"type":"FormMultiselect","field":"variant","config":{"label":"Button Variant Style","helper":"The variant determines the appearance of the button","options":[{"value":"primary","content":"Primary"},{"value":"secondary","content":"Secondary"},{"value":"success","content":"Success"},{"value":"danger","content":"Danger"},{"value":"warning","content":"Warning"},{"value":"info","content":"Info"},{"value":"light","content":"Light"},{"value":"dark","content":"Dark"},{"value":"link","content":"Link"}]}},{"type":"FormInput","field":"conditionalHide","config":{"label":"Visibility Rule","helper":"This control is hidden until this expression is true"}},{"type":"DeviceVisibility","field":"deviceVisibility","config":{"label":"Device Visibility","helper":"This control is hidden until this expression is true"}},{"type":"FormInput","field":"customFormatter","config":{"label":"Custom Format String","helper":"Use the Mask Pattern format <br> Date ##\/##\/#### <br> SSN ###-##-#### <br> Phone (###) ###-####","validation":null}},{"type":"FormInput","field":"customCssSelector","config":{"label":"CSS Selector Name","helper":"Use this in your custom css rules","validation":"regex: [-?[_a-zA-Z]+[_-a-zA-Z0-9]*]"}},{"type":"FormInput","field":"ariaLabel","config":{"label":"Aria Label","helper":"Attribute designed to help assistive technology (e.g. screen readers) attach a label"}},{"type":"FormInput","field":"tabindex","config":{"label":"Tab Order","helper":"Order in which a user will move focus from one control to another by pressing the Tab key","validation":"regex: [0-9]*"}}],"editor-control":"FormSubmit","editor-component":"FormButton"}]}],"computed":[],"custom_css":null,"created_at":"2024-03-01T18:23:06+00:00","updated_at":"2024-03-01T18:23:13+00:00","status":"ACTIVE","key":null,"watchers":[],"translations":null,"is_template":0,"asset_type":null,"projects":"[]","categories":[{"id":1,"uuid":"9b7483c1-a21f-4103-91d9-7ba629ad8d3e","name":"Uncategorized","status":"ACTIVE","is_system":0,"created_at":"2024-02-29T22:54:50+00:00","updated_at":"2024-02-29T22:54:50+00:00","pivot":{"category_type":"ProcessMaker\\Models\\ScreenCategory","assignable_id":32,"category_id":1}}]}],"screen_categories":[],"scripts":[]}

0 comments on commit e97b7b7

Please sign in to comment.