add the changed code from _InitialData initialData.md

parent 47103506
......@@ -66,22 +66,8 @@ module.exports = function (session) {
## Create a folder for a submenu
Create a folder Departments on your desktop City Requests.
To do this in `010_create_navshortcuts.js` file between the lines
```javascript
desktopID = conn.insert({
//...
}
});
```
and
```javascript
}
else { //else display a message
console.info('\t\tuse existed desktop with code `CityReq_desktop`', desktopID);
}
```
add the following code
To do this in `010_create_navshortcuts.js` file
Add the following code to `module.exports = function (session)` below the desktop creating
```javascript
folderID = conn.lookup('ubm_navshortcut', 'ID', {expression: 'code', condition: 'equal', values: {code: 'req_departments_folder'}});
......@@ -111,21 +97,7 @@ folderID = conn.lookup('ubm_navshortcut', 'ID', {expression: 'code', condition:
To the Departments folder add the shortcut Departments
To do this in `010_create_navshortcuts.js` file between the lines
```javascript
folderID = conn.insert({
//...
}
});
```
and
```javascript
}
else { //else display a message
console.info('\t\tuse existed folder with code `req_departments_folder`', folderID);
}
```
To do this in `010_create_navshortcuts.js` file below the folder creating
add the following code
```javascript
......@@ -164,13 +136,6 @@ To run the script, run the command in the root of project
The following message should appear in the console:
![creating_shortcut_console](img/initialData/creating_shortcut_console.PNG)
If you see the following message
![desktop_exist_error](img/initialData/desktop_exist_error.png)
This means that the desktop was created earlier. You can
* delete the created menu items manually in the admin panel
* execute the file `init.cmd` that will reinitialize the entire project.In this case, all the shortcuts, roles and users previously created in the admin panel are deleted. Forms, reports and charts remain in the folder as files.
<a name = 'dir'></a>
......@@ -197,16 +162,30 @@ Create the javascript-file `\models\requests\_initialData\020_fill_departments.j
```javascript
module.exports = function(session){
const path = require('path')
const fs = require('fs')
const {dataLoader, csv, argv} = require('@unitybase/base')
let conn = session.connection;
let fn = path.join(__dirname, '/req_depart.csv')
let fContent = fs.readFileSync(fn)
if (!fContent) { throw new Error(`File ${fn} is empty or not exist`) }
fContent = fContent.trim()
let csvData = csv.parse(fContent)
//check existing records in the DB
let notExisted = csvData.filter(
(row) => !conn.lookup('req_depart', 'ID',
conn.Repository('req_depart').where('name', '=', row[0]).ubql().whereList
)
)
if(!notExisted){
console.info('\t\tFill Departments field (req_depart)');
dataLoader.loadArrayData(conn, notExisted, 'req_depart', 'name;postAddr;phoneNum'.split(';'), [0,1,2], 1);
}
else {
console.info('\t\tall records are existing in DB (req_depart)');
}
var
csvLoader = require('@unitybase/base').dataLoader,
conn = session.connection;
console.info('\t\tFill Departments field (req_depart)');
csvLoader.loadSimpleCSVData(conn, __dirname + '/req_depart.csv', 'req_depart', 'name;postAddr;phoneNum'.split(';'), [0,1,2], 1);
};
```
To run the script, run the command in the root of project
......@@ -215,15 +194,6 @@ To run the script, run the command in the root of project
The following message should appear in the console:
![creating_shortcut_console](img/initialData/fill_depart_console.PNG)
If you see the following message
![fill_depart_console_error](img/initialData/fill_depart_console_error.PNG)
This means that the departments with such names were created earlier. You can
* delete the department`s list manually in the admin panel
* do not update anything if the list already exists
## Using Enum in models.
......@@ -268,13 +238,28 @@ Create the file `\models\requests\_initialData\015_fill_enum-req.js` with follo
```javascript
module.exports = function(session){
"use strict";
var
csvLoader = require('@unitybase/base').dataLoader,
conn = session.connection;
console.info('\t\tFill enumeration for RequestList model');
csvLoader.loadSimpleCSVData(conn, __dirname + '/ubm_enum-req.csv', 'ubm_enum', 'eGroup;code;name;sortOrder'.split(';'), [0, 1, 2, 3]);
const path = require('path')
const fs = require('fs')
const {dataLoader, csv, argv} = require('@unitybase/base')
let conn = session.connection;
let fn = path.join(__dirname, '/ubm_enum-req.csv')
let fContent = fs.readFileSync(fn)
if (!fContent) { throw new Error(`File ${fn} is empty or not exist`) }
fContent = fContent.trim()
let csvData = csv.parse(fContent)
let notExisted = csvData.filter(
(row) => !conn.lookup('ubm_enum', 'code',
conn.Repository('ubm_enum').where('code', '=', row[1]).ubql().whereList
)
)
if(!notExisted){
console.info('\t\tFill enumeration for RequestList model');
dataLoader.loadArrayData(conn, notExisted, 'ubm_enum', 'eGroup;code;name;sortOrder'.split(';'), [0, 1, 2, 3]);
}
else {
console.info('\t\tall records are existing in DB (ubm_enum)');
}
};
```
......@@ -282,7 +267,6 @@ module.exports = function(session){
If you execute the command `ubcli initialize -u admin -p admin -host http://localhost:888 -m RequestList`
![fill_enum_console](img/initialData/fill_enum_console.PNG)
The error message means that the department list is already full. In order for the script in the file `020_fill_departments.js` to not be executed, you can put _ before the file name.
<a name = 'localize'></a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment