digiclear:managingmachines:parsing

Parsing (JavaScript)

You can write a parser in JavaScript that will be used to parse a file and to fill automatically the form of a process

here is an example of javascript program for the machine Sentech SI500


here is an nextralFluor1JS of javascript program for the machine Nextral Fluor 1

Your javascript code will be loaded as a function. This function has access to several parameters :

  • fileContent : this parameter contains the content of the parsed file, either a String or an ArrayBuffer depending on the type of file (selected below).
  • fileName : this parameter contains the name of the parsed file.
  • fileSize : this parameter contains the size of the parsed file in bytes.
  • operationType : this parameter contains the type of operation currently selected (process, maintenance, etc …). You cannot (yet) choose the type of operation from inside the parser, so use this to raise an error if the incorrect type is selected.

Your parser function is expected to return an object which looks like the following :

{
	key : value,
	key : value,
	...
	key : value,
	
	"operation-samples": [
		{
			key : value,
			key : value,
			...
			key : value
		},
		{...},
		...
	]
}

Where each key is the name in the database of the value (as defined in the template), and its value is the value parsed from the file.

You can add the attribute operation-samples if you want to set sample related parameters. operation-samples must be an array, and that array must contain objects following the previous key : value rules. each object in the array will create a new sample tab in the form, allowing the user to select which sample was used.

If the parser encounter something that isn't right (wrong file supplied, wrong type of operation, etc), you can throw an error. That error will then be displayed to the user in a red alert box (if your parser itself contains errors, these will also be displayed in that box, allowing you to debug it).

if (operationType!="process")
	{
		throw new Error("operationType must be process");
	}

To interact with the user you can also use the confirm, alert, and the prompt functions.

var test = prompt (" Test de valeur " );

var yn = confirm (" Voulez vous continuer ?");

  • digiclear/managingmachines/parsing.txt
  • Last modified: 2020/06/11 18:15
  • by 127.0.0.1