Advertisement
Savelyev_Vyacheslav

client OverviewWidget

Jun 26th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.90 KB | None | 0 0
  1. /*
  2. update()
  3. getList()
  4. isReadOnly()
  5. isNotReadOnly()
  6. isMandatory()
  7. isNotMandatory()
  8. All()
  9. sortValues()
  10. sortName()
  11. sortSection()
  12. sortLabel()
  13. sortReadOnly()
  14. sortMandatory()
  15. */
  16. (async () => {
  17. window.s_widget_custom = window.s_widget_custom || {};
  18. await s_widget.setFieldValue('nextState', '');
  19. await s_widget.setFieldValue('currentID', s_form.sysId);
  20. await s_widget.setFieldValue('tableName', s_form.getTableName());
  21. await s_widget.setFieldValue('sections', s_form.getSectionNames());
  22.  
  23. await s_widget.setFieldValue('formId', s_form.formId);
  24. await s_widget.serverUpdate();
  25. let names = s_widget.getFieldValue('names');
  26. let avalible = s_widget.getFieldValue('avalible');
  27. let arrNames = [];
  28. for (const [key, value] of Object.entries(avalible)) {
  29. value.forEach(v => arrNames.push(v) );
  30. }
  31. function readonlyOfNames(names) {
  32. let readonlyOfNames = [];
  33. names.forEach(value => readonlyOfNames.push(s_form.isReadonly(value)))
  34. return readonlyOfNames;
  35. }
  36.  
  37. window.overview = {
  38. fields: s_widget.getFieldValue('fields'),
  39. names: getNames(s_widget.getFieldValue('names')), // именя доступных полей
  40. readonlyOfNames: readonlyOfNames(names), // массив true false для readOnly полей из массива "names"
  41. mandatoryServer: s_widget.getFieldValue('mandatory'),
  42. getChoice(val){ console.table(
  43. s_widget.getFieldValue('choice')[val].split(';') )//
  44. },
  45. visibl: getVisible(names),
  46. avalible: avalible,
  47. sectionsNotvisible: Object.keys(avalible).filter(value => !s_form.isSectionVisible(value)),
  48. list: '',
  49. start() {
  50. s_widget.setFieldValue('isShow', 'true');
  51. this.getList();
  52. {test: "test"};
  53. },
  54. update() {
  55. this.visibl = getVisible(this.names);
  56. console.log("\u001b[1;31m updated")
  57. },
  58. nextState(state){switchStatus(state)},
  59. getList(fieldName = '') {
  60. this.update();
  61. let filter = this.visibl.filter(value => value.includes(fieldName));
  62. this.list = getList(filter);
  63. let table = [''];
  64. this.list.forEach(value => getTable(table, value));
  65.  
  66. let container = document.querySelector(`#template`);
  67. container.innerHTML = table[0];
  68. },
  69. isReadOnly() {
  70. this.update();
  71. const printSYS = this.visibl.filter(value => s_form.isReadonly(value) )
  72. console.log(printSYS);
  73. const printLAB = [];
  74. printSYS.forEach(value => printLAB.push(s_form.getLabelOf(value)))
  75. console.log( printLAB );
  76. },
  77. isNotReadOnly() {
  78. this.update();
  79. const printSYS = this.visibl.filter(value => !s_form.isReadonly(value) )
  80. console.log(printSYS);
  81. const printLAB = [];
  82. printSYS.forEach(value => printLAB.push(s_form.getLabelOf(value)))
  83. console.log( printLAB );
  84. },
  85. isMandatory() {
  86. this.update();
  87. const printSYS = this.visibl.filter(value => s_form.isMandatory(value))
  88. console.log(printSYS);
  89. const printLAB = [];
  90. printSYS.forEach(value => printLAB.push(s_form.getLabelOf(value)))
  91. console.log( printLAB );
  92. },
  93. isNotMandatory() {
  94. this.update();
  95. const printSYS = this.visibl.filter(value => !s_form.isMandatory(value))
  96. console.log(printSYS);
  97. const printLAB = [];
  98. printSYS.forEach(value => printLAB.push(s_form.getLabelOf(value)))
  99. console.log( printLAB );
  100. },
  101. All() {
  102. this.update();
  103. console.log(this.visibl);
  104. const printLAB = [];
  105. this.visibl.forEach(value => printLAB.push(s_form.getLabelOf(value)))
  106. console.log( printLAB );
  107. },
  108. sortValues(fieldName = '') {
  109. this.update();
  110. let filter = this.visibl.filter(value => value.includes(fieldName));
  111. this.list = getList(filter);
  112. let table = [''];
  113. this.list.sort((a, b) => `${b[4]}${b[5]}`.length - `${a[4]}${a[5]}`.length).forEach(value => getTable(table ,value));
  114.  
  115. let container = document.querySelector(`#template`);
  116. container.innerHTML = table[0];
  117. },
  118. sortName(fieldName = '') {
  119. this.update();
  120. let filter = this.visibl.filter(value => value.includes(fieldName));
  121. this.list = getList(filter);
  122. let table = [''];
  123. this.list.sort((a, b) => a[2].charCodeAt() - b[2].charCodeAt()).forEach(value => getTable(table ,value));
  124.  
  125. // const printSYS = this.visibl.sort((a, b) => a[0].charCodeAt() - b[0].charCodeAt())
  126. // console.log(printSYS);
  127. // const printLAB = [];
  128. // printSYS.forEach(value => printLAB.push(s_form.getLabelOf(value)))
  129. // console.log( printLAB );
  130.  
  131.  
  132. let container = document.querySelector(`#template`);
  133. container.innerHTML = table[0];
  134. },
  135.  
  136. sortSection(fieldName = '') {
  137. this.update();
  138. let filter = this.visibl.filter(value => value.includes(fieldName));
  139. this.list = getList(filter);
  140. let table = [''];
  141. this.list.sort((a, b) => a[6].charCodeAt() - b[6].charCodeAt()).forEach(value => getTable(table ,value));
  142.  
  143. let container = document.querySelector(`#template`);
  144. container.innerHTML = table[0];
  145. },
  146.  
  147. sortLabel(fieldName = '') {
  148. this.update()
  149. let filter = this.visibl.filter(value => value.includes(fieldName));
  150. this.list = getList(filter);
  151. this.list.sort((a, b) => a[3].charCodeAt() - b[3].charCodeAt()).forEach(value => p(value));
  152. },
  153. sortReadOnly(fieldName = '') {
  154. this.update();
  155. let filter = this.visibl.filter(value => value.includes(fieldName));
  156. this.list = getList(filter);
  157. let table = [''];
  158. this.list.sort((a, b) => b[1] - a[1]).forEach(value => getTable(table ,value));
  159.  
  160. let container = document.querySelector(`#template`);
  161. container.innerHTML = table[0];
  162. },
  163. sortMandatory(fieldName = '') {
  164. this.update();
  165. let filter = this.visibl.filter(value => value.includes(fieldName));
  166. this.list = getList(filter);
  167. let table = [''];
  168. this.list.sort((a, b) => b[0] - a[0]).forEach(value => getTable(table ,value));
  169.  
  170. let container = document.querySelector(`#template`);
  171. container.innerHTML = table[0];
  172. },
  173. to_fields(arrfields) {
  174. let fields = '';
  175. arrfields.forEach(value => fields += `${value}\n`);
  176. console.log(fields);
  177. },
  178. to_seeFields(arrfields, type = 'readonly', bool = 'true') {
  179. let seeFields = '';
  180. arrfields.forEach(value => seeFields += `${value}: {${type}: ${bool}},\n`);
  181. console.log(seeFields);
  182. },
  183. makeMatrix(name, del = ''){// удалить вывести
  184. let matrix = [];
  185. if (del === '') {
  186. if (localStorage.getItem(name) === null) {localStorage.setItem(name, 'FIELDs ,' + this.names + ';')}
  187. localStorage.setItem(name, localStorage.getItem(name) + s_form.getDisplayValue('state') + ',' + readonlyOfNames(names) + ';'); // readonlyOfNames(names) - массив [true false]readOnly для полей из массива "names"
  188. }
  189. if (del === 'get') {
  190. let colums = localStorage.getItem(name).split(';').filter(value => value != ['']);
  191. colums.forEach(value => matrix.push( value.split(',') ))
  192. matrix = _.zip(...matrix)
  193. console.table(matrix)
  194. }
  195. if (del === 'del') {eval (`delete localStorage.${name}`)}
  196. },
  197. stateMatrix() { // localStorage.setItem('states', ['-2','8','6','10','7','3','4','2','0'])
  198. // localStorage.setItem('states', ['-2', '-1', '1', '2', '7', '9', '10']) Change Requests http://localhost:3000/record/sys_business_rule/165789658610849621
  199. let way = localStorage.getItem('states').split(',');
  200. let currentMay = s_form.getValue('state');
  201. let next = way[way.indexOf(currentMay)+1];
  202. console.log(s_form.getDisplayValue('state') + s_form.getValue('state') + ' № '+ (way.indexOf(currentMay)+1))
  203. setTimeout(() => {
  204. if (next == undefined ) return;
  205. s_widget.setFieldValue('nextState', next);
  206. s_widget.serverUpdate();
  207. s_go.reloadWindow();
  208. }, 2000)
  209.  
  210. },
  211. stateFlou(state_s) {
  212. let duration = 1000;
  213. var s, myStringArray = state_s;
  214. for (s of myStringArray) {
  215. eval(`setTimeout(() => { overview.nextState('${s}')}, ${duration})`)
  216. //console.log(`setTimeout(() => { overview.nextState('${s}')}, ${duration})`)
  217. duration += 5000;
  218. }
  219. },
  220.  
  221. };
  222.  
  223.  
  224. console.log('overview.start()')
  225.  
  226.  
  227. s_widget_custom.reject = () => {
  228. s_widget.setFieldValue('isShow', 'false');}
  229. s_widget_custom.Mandatory = () => { overview.sortMandatory(); }
  230. s_widget_custom.ReadOnly = () => { overview.sortReadOnly(); }
  231. s_widget_custom.Names = () => { overview.sortName(); }
  232. s_widget_custom.Values = () => { overview.sortValues(); }
  233. s_widget_custom.Sections = () => { overview.sortSection(); }
  234.  
  235. s_widget_custom.isReadOnly = () => { overview.isReadOnly(); }
  236. s_widget_custom.isNotReadOnly = () => { overview.isNotReadOnly(); }
  237. s_widget_custom.isMandatory = () => { overview.isMandatory(); }
  238. s_widget_custom.isNotMandatory = () => { overview.isNotMandatory(); }
  239. s_widget_custom.All = () => { overview.All(); }
  240.  
  241. //flou
  242. // overview.stateMatrix();
  243. // overview.makeMatrix('new1');
  244. })();
  245.  
  246. function getNames(names) {
  247. return names.filter(value => value);
  248. }
  249.  
  250. function getVisible(names) {
  251. return names.filter(value => s_form.isVisible(value));
  252. }
  253.  
  254. function getList(visibl) {
  255. let info = []
  256. visibl.forEach(value => info.push([s_form.isMandatory(value), s_form.isReadonly(value), value, s_form.getLabelOf(value), s_form.getDisplayValue(value), s_form.getValue(value), getVisiblSection(value)]));
  257. return info;
  258. }
  259.  
  260.  
  261. function getTable(table, value) {
  262. let fielsValue = value[4] && value[5] ? value[4] + ' = ' + value[5] : value[4] + value[5];
  263. const mandatory = value[0] ? 'TRUE' : 'false';
  264. const raedOnly = value[1] ? 'TRUE' : 'false';
  265. let bg = '';
  266.  
  267. if (value[0] || value[1]) {
  268. bg = 'style="font-weight:bold;transform: scale(1, 1.2); "'
  269. }
  270.  
  271. //if(!s_form.isSectionVisible(getVisiblSection(value[2])) && s_form.getSections().length > 1) return;
  272. let template = `<tr ${bg}>
  273. <td class="Mandatory"> ${mandatory} </td>
  274. <td class="ReadOnly"> ${raedOnly} </td>
  275. <td class="Names"> ${value[2] + ' ' + value[3]} </td>
  276. <td class="Values"> ${fielsValue} </td>
  277. <td class="Sections"> ${value[6]} </td>
  278. </tr>`;
  279. table[0] += template;
  280. }
  281.  
  282. function getVisiblSection(field) {
  283. let sections = Object.keys(overview.avalible)
  284. const section = sections.filter(value => overview.avalible[value].includes(field));
  285. return section[0];
  286. }
  287.  
  288. async function switchStatus(state) {
  289. await s_widget.setFieldValue('nextState', state);
  290. await s_widget.serverUpdate();
  291. await s_form.setValue('state', state);
  292. await s_form.save();
  293. await console.log(s_form.getDisplayValue('state'))
  294. await s_go.reloadWindow();
  295. }
  296.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement