### Install Total.js Framework 5 Source: https://github.com/totaljs/framework5/blob/main/README.md This snippet shows how to install the Total.js framework version 5 using npm. It's a prerequisite for using the framework in your Node.js projects. ```bash $ npm install total5 ``` -------------------------------- ### RESTBuilder Example: xhr().callback() Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md An example demonstrating how to make a GET request using RESTBuilder, chain the xhr() method, and handle the response using a callback function. ```javascript RESTBuilder.GET('https://www.totaljs.com').xhr().callback(function(err, response) { console.log(err, response); }); ``` -------------------------------- ### Basic NEWACTION Example with Query and Params Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md An example demonstrating the usage of NEWACTION with query and parameter schemas. It shows how to define expected query and parameter fields and includes a basic action function that utilizes the provided context. ```javascript NEWACTION('Find', { query: 'page:Number, sort:String', params: 'projectid:String', route: '+API ?', action: function($) { // $ {Options} Documentation: https://docs.totaljs.com/total5/IbGpBV25x60f/ // $.query {Object key:value} // $.user {Object key:value} // $.params {Object key:value} // $.model {Object key:value} or model "is prepared according to the input data schema" // $.headers {Object key:value} // $.ip {String} // $.files {Array} // $.invalid(error_or_http_status) // $.callback({ success: true }); // $.success(data); // $.redirect(url); $.success(); } }); ``` -------------------------------- ### HTML and CSS for Application Start Display Source: https://github.com/totaljs/framework5/blob/main/pause.html Provides the basic HTML structure and CSS styling for displaying a 'Please wait' message and a countdown timer during application startup. It includes styles for the body, table layout, animation, and the timer element itself. ```html html,body { font: normal normal 14px Arial; background-color: white; height: 100%; margin: 0; padding: 0; font-smoothing: antialiased; } .table { display: table; width: 100%; height: 100%} .cell { display:table-cell;vertical-align:middle;text-align:center} table { max-width: 300px; margin: 20px auto; width: 100%; border:1px solid #E0E0E0; border-collapse: collapse; font-size: 12px; } table td { border: 1px solid #E0E0E0; padding: 6px 8px; text-align: center; } table td:first-child { text-align: left; width: 85%; } .anim { animation: anim 2s infinite; } .text { color: #A0A0A0; font-size: 10px; margin-bottom: 3px; } #time { font-size: 60px; font-weight: bold; margin-bottom: 10px; background-color: #000; color: #FFF; padding: 8px 15px; min-width: 70px; text-align: center; border-radius: 10px; position: relative; display: inline-block; border-bottom: 5px solid #D0D0D0; } @keyframes anim { 0% { transform:scale(1); } 50%{ transform:scale(1.5) rotate(180deg); color:gray } 100%{ transform:scale(1); } } ``` -------------------------------- ### Total.js Plugin Action Example (Todo List) Source: https://github.com/totaljs/framework5/blob/main/docs/plugin.md An example of defining a server-side action within a Total.js plugin to list tasks. It utilizes the `NEWACTION` helper to define the action's name, route, and the asynchronous function to fetch data using `DATA.list().autoquery()`. ```javascript exports.name = '@(Todo)'; exports.icon = 'ti ti-check'; exports.position = 1; exports.visible = user => user.permissions.includes('todo'); exports.permissions = [{ id: 'todo', name: 'ToDo' }]; // Action example NEWACTION('Todo|list', { name: 'List of tasks', route: '+API ?', action: async function($, model) { // $ {Options} Documentation: https://docs.totaljs.com/total5/IbGpBV25x60f/ // $.query {Object key:value} // $.user {Object key:value} // $.params {Object key:value} // $.model {Object key:value} or model "is prepared according to the input data schema" // $.headers {Object key:value} // $.ip {String} // $.files {Array} // $.invalid(error_or_http_status) // $.callback({ success: true }); // $.success(data); // $.redirect(url); // It creates a list with pagination and filtering and sorting of the fields defined in the .autoquery() method. let response = await DATA.list('tbl_todo').autoquery($.query, 'id:String, name:String, body:String, iscompleted:Boolean, createdby:String, updatedby:String, completedby:String, dtcompleted:Date, dtcreated:Date, dtupdated:Date', 'dtcreated_desc', 100).promise($); $.callback(response); } }); ``` -------------------------------- ### SQL Table Creation with Total.js Conventions Source: https://github.com/totaljs/framework5/blob/main/docs/databases.md Example of a PostgreSQL table creation script adhering to Total.js naming conventions and field ordering. It includes identifiers, main fields, numbers, booleans, and dates, with specific data types and default values. ```SQL CREATE TABLE "public"."tbl_channel_message" ( -- IDENTIFIERS FIRST "id" text NOT NULL, "userid" text, "channelid" text, "openplatformid" text, -- MAIN FIELDS "body" text, -- NUMBERS "countupdate" INT2 DEFAULT 0, "countviews" INT2 DEFAULT 0, -- BOOLEANS "isrobot" bool DEFAULT FALSE, "ismobile" bool DEFAULT FALSE, "ispinned" bool DEFAULT FALSE, "isremoved" bool DEFAULT FALSE, -- AND LAST DATES "dtupdated" timestamp, "dtremoved" timestamp, "dtcreated" timestamp DEFAULT timezone('utc'::text, now()), -- DO NOT FORGET FOR FOREIGN KEYS CONSTRAINT ... CONSTRAINT ... PRIMARY KEY ("id") ); ``` -------------------------------- ### Python Script Loading and Execution Source: https://github.com/totaljs/framework5/blob/main/changelog.txt This snippet demonstrates the support for Python scripts within the Total.js framework. It includes the addition of the PYPELINE method, which allows for starting a Python process with specified options. ```javascript added support for Python scripts in the `pypelines` folder added `PYPELINE(name, [options])` method starts a python process ``` -------------------------------- ### Configure Routing with ROUTE Directive (JavaScript) Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md This example demonstrates how to configure routes for different HTTP methods and paths using the `ROUTE` directive in Total.js. It shows how to map paths to specific actions and handle different HTTP verbs like `+API`, `+GET`, and `+POST`. ```javascript ROUTE('+API /api/ --> action1'); ROUTE('+GET /api/products/ --> action1 action2 action3'); ROUTE('+POST /api/products/add/ --> action1 action2 (response) action3'); ``` -------------------------------- ### Example: Find users by age range Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Searches for users within a specific age range and who are not removed, using callbacks for results. ```javascript // Search for users between 20 and 30 years old who have not been removed. "DATA.find()" returns always Array of objects (rows). DATA.find('tbl_user').where('isremoved', false).between('age', 20, 30).callback(function(err, response) { // response {Array of objects} console.log(err, response); }); ``` -------------------------------- ### Unify debug and release mode Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Unifies debug and release modes by using monitoring files. Monitoring can be disabled via `options.watcher = false` in the start script. ```javascript options.watcher = false ``` -------------------------------- ### Total.js Plugin Server-Side Definition (index.js) Source: https://github.com/totaljs/framework5/blob/main/docs/plugin.md Defines the core server-side logic for a Total.js plugin. Includes properties for name, icon, position, visibility, permissions, and installation hooks. The `visible` function controls client-side access based on user roles or permissions. ```javascript exports.name = '@(Todo)'; // A plugin name. The markup "@(your_text)" is automatically localized. It's the Total.js localization markup. exports.icon = 'ti ti-check'; // A plugin icon. exports.position = 1; // A position index in the navigation. exports.hidden = false; // Although this property "exports.hidden" can hide the plugin in the menu, but it will still be evaluated on the client side. exports.import = 'extensions.html'; // Optional. This property can contain a file name from the "plugin/todo/public/" folder. The client-side library imports that file while the web app loads. It's intended for very specific cases, and most plugins don't use it. exports.visible = function(user) { // In this handler, we can check the permissions for accessing this plugin on the client side. It's superior to the "exports.hidden" property. // IMPORTANT: The "user.sa {Boolean}" or "user.su {Boolean}" sees everything. return user.sa || user.permissions.includes('myitems_view'); }; exports.permissions = [{ id: 'myitems_view', name: 'View My Items' }, { id: 'myitems_edit', name: 'Edit My Items' }]; // A custom permissions, It's only targeted for the Total.js OpenPlatform (SSO portal). exports.install = function() { // Some specific routes can be defined here, such as file handlers and uploading. }; ``` -------------------------------- ### Total.js Template Loop Source: https://github.com/totaljs/framework5/blob/main/pause.html A server-side template snippet using Total.js syntax to iterate over a 'model'. If the model contains items, each item 'm' is rendered. This is a common pattern for dynamic content generation in Total.js applications. ```totaljs @{foreach m in model} @{end} @{m} ``` -------------------------------- ### Example: Find user by name Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Searches for a single user by name, assuming 'DATA.read()' returns a single object. ```javascript // Search for a user named Peter who has not been removed. "DATA.read()" returns always single object (row). ``` -------------------------------- ### JavaScript Countdown Timer Source: https://github.com/totaljs/framework5/blob/main/pause.html Implements a client-side countdown timer that decrements from 10 to 0. When the counter reaches zero, it reloads the current page. This script is intended to be used during application startup. ```javascript var counter = 10; setInterval(function() { if (counter < 0) return; if (counter === 0) window.location.reload(); else time.innerHTML = counter + ''; counter--; }, 1000); ``` -------------------------------- ### Total.js: RESTBuilder GET Request Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Creates an HTTP GET request to an external endpoint using RESTBuilder. Requires an absolute URL. ```javascript RESTBuilder.GET(url); ``` -------------------------------- ### JavaScript GUID Generation Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Creates a unique identifier (GUID) which is at least 12 characters long. It includes a timestamp, minute counter, and a hash with a checksum. An optional length parameter can specify the maximum length. ```javascript let guid1 = GUID(); let guid2 = GUID(10); ``` -------------------------------- ### NEWMIDDLEWARE Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Notes the addition of the missing NEWMIDDLEWARE() method. ```javascript added missing method `NEWMIDDLEWARE()` ``` -------------------------------- ### Extended Ctrl File System Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Extends the `ctrl.filefs()` method to return the `opt` object. This enhancement likely provides more detailed information or access to options used during file system operations within the controller. ```javascript const options = ctrl.filefs(); // Use options object ``` -------------------------------- ### Ctrl Image Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the `ctrl.image(opt)` method for handling image-related operations within a controller. The `opt` parameter likely allows for configuration of image processing, such as resizing, cropping, or format conversion. ```javascript ctrl.image({ width: 100, height: 100, format: 'png' }); ``` -------------------------------- ### Add $.ctrl(ctrl_instance) method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the `$.ctrl(ctrl_instance)` method, allowing for the association of a controller instance with the current context. ```javascript $.ctrl(ctrl_instance) ``` -------------------------------- ### Extend ViewEngine with view.renderlayout() Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Extends the `ViewEngine` by adding the `view.renderlayout(name, content)` method for rendering layouts with provided content. ```javascript view.renderlayout(name, content) ``` -------------------------------- ### View Engine @{meta} Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Notes the addition of the missing ViewEngine method `@{meta(...)}`. ```javascript added missing ViewEngine `@{meta(...)}` method ``` -------------------------------- ### Total.js Framework File Loading Fixes Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Addresses issues with loading plugin files, ensuring only `.js` files are loaded and excluding `.DS_STORE` files. ```javascript - fixed loading plugin files (only `.js` files will load) - removed loading of `.DS_STORE` files in plugins ``` -------------------------------- ### FILESTORAGE Clone Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the FILESTORAGE().clone(id, newid, [callback]) method for creating a copy of a file storage entry. ```javascript added `FILESTORAGE().clone(id, newid, [callback])` method ``` -------------------------------- ### Total.js Framework COMPONENTANTOR Download Procedure Update Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Updates the download procedure in the COMPONENTANTOR() method for improved reliability. ```javascript - updated download procedure in the `COMPONENTANTOR()` method ``` -------------------------------- ### Add CMS.run() method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces a new method `CMS.run(widget_html)` for executing CMS widgets, likely for content management functionalities. ```javascript CMS.run(widget_html) ``` -------------------------------- ### RESTBuilderInstance: auth(user_or_token, [password]) Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Creates an 'Authorization' header for HTTP authentication or token-based authentication. Accepts a username/token and an optional password. Returns the RESTBuilderInstance object for chaining. ```javascript builder.auth('petersirka', '123456'); builder.auth('Bearer YOUR_AUTH_TOKEN'); ``` -------------------------------- ### NEWACTION Syntax and Options Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md Defines the syntax for the NEWACTION method, including the required ID and the optional options object. The options object allows for detailed configuration of the action's behavior, including data schemas, routing, and permissions. ```javascript NEWACTION(id, options) ``` -------------------------------- ### Total.js Framework HEAD Method Support Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for the HTTP `HEAD` method, allowing clients to retrieve headers without the response body. ```javascript - added support for `HEAD` method ``` -------------------------------- ### F.backup Ignore List Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Improves the F.backup() method by adding an internal ignore list for common backup exclusion files like .DS_Store and .gitignore. ```javascript improved `F.backup()` by adding internal ignore list for `.DS_Store` and `.gitignore` files ``` -------------------------------- ### View Engine @{import} Method Enhancement Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Details the enhancement of the `@{import()}` method to support importing CSS and JS files with automatic cache-busting timestamps appended to the URL. ```javascript extended `@{import()}` method now supports `@style_name.css` and `@script_name.js` (due to HTTP cache reasons, it automatically appends the argument `?ts=start_app_timestamp` to the URL) ``` -------------------------------- ### Schema/Auth Options Hostname Replacement Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Replaces the `$.hostname` property with a method in the Schema/Auth Options for consistency and potential future enhancements. ```javascript replaced `$.hostname` property with a method in the Schema/Auth Options ``` -------------------------------- ### List Todo Tasks Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md Retrieves a list of todo tasks from the 'tbl_todo' database table. It supports pagination, filtering, and sorting based on the provided query parameters. The response includes task details like ID, name, body, completion status, and timestamps. ```javascript NEWACTION('Todo|list', { name: 'List of tasks', route: '+API ?', action: async function($, model) { let response = await DATA.list('tbl_todo').autoquery($.query, 'id:String, name:String, body:String, iscompleted:Boolean, createdby:String, updatedby:String, completedby:String, dtcompleted:Date, dtcreated:Date, dtupdated:Date', 'dtcreated_desc', 100).promise($); $.callback(response); } }); ``` -------------------------------- ### Add PROMISIFY() and $.promisify() methods Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces `PROMISIFY(fn, [a], [b])` and `$.promisify(fn, [a], [b])` methods for converting callback-based functions into Promise-based functions. ```javascript PROMISIFY(fn, [a], [b]) ``` ```javascript $.promisify(fn, [a], [b]) ``` -------------------------------- ### Add U.paginate() method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces a new utility method `U.paginate(page, pages, [max])` for handling pagination logic. ```javascript U.paginate(page, pages, [max]) ``` -------------------------------- ### Add FILESTORAGE().copy() method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the `FILESTORAGE().copy(id, path, [callback(err, meta)])` method for copying files within the file storage system. ```javascript FILESTORAGE().copy(id, path, [callback(err, meta)]) ``` -------------------------------- ### QueryBuilder Pipe Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the QueryBuilder.pipe() method as an alias for QueryBuilder.callback(), providing an alternative way to handle callback operations. ```javascript added `QueryBuilder.pipe()` method as alias to `QueryBuilder.callback()` ``` -------------------------------- ### Add support for plugins in TEMPLATE() Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for plugins within the `TEMPLATE()` method, enabling extensibility and customization of template rendering processes. ```javascript TEMPLATE() ``` -------------------------------- ### Action Pipe Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the Action.pipe() method as an alias for Action.callback(), simplifying callback management within actions. ```javascript added `Action.pipe()` method as alias to `Action.callback()` ``` -------------------------------- ### Total.js Framework CONF.$root Functionality Fix Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes the functionality of CONF.$root, ensuring correct configuration loading. ```javascript - fixed `CONF.$root` functionality ``` -------------------------------- ### Total.js Framework Auto Script Loader Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds an auto script loader for the `extensions` and `transforms` directories, simplifying the management of scripts. ```javascript - added auto script loader for `extensions` directory - added auto script loader for `transforms` directory ``` -------------------------------- ### Total.js Framework Specific File Extension Routing Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces support for routing specific file extensions using the `ROUTE('FILE *.php', ...)` syntax. ```javascript - added support for handling specific file extensions in the form `ROUTE('FILE *.php', ...)` ``` -------------------------------- ### QueryBuilder Search with ILIKE Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Adds a standard SQL comparison using ILIKE for case-insensitive searching. Supports pattern matching. ```javascript builder.search(column, value, [operator]); // The method adds a standard SQL comparison, such as "COLUMN ILIKE VALUE". // column {String} a column name. // value {String} a value for comparison. // operator {String} optional, possible values: "*" throughout the text, "beg" at the beginning, and "end" at the end. // returns {QueryBuilder} object; ``` -------------------------------- ### Custom View Engine Helpers Source: https://github.com/totaljs/framework5/blob/main/changelog.txt This section highlights the ability to define custom helper functions for the Total.js View engine. These helpers can be registered using DEF.helpers. ```javascript added support for custom View engine helpers `DEF.helpers.myhelper` ``` -------------------------------- ### Add Utils.filestreamer() Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the `Utils.filestreamer(filename, onbuffer(buffer, next), onend, [buffer_size])` utility for efficient file streaming. ```javascript Utils.filestreamer(filename, onbuffer(buffer, next), onend, [buffer_size]) ``` -------------------------------- ### Improve user-agent parser Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Enhances the user-agent parser to include support for new headers like `Sec-CH-UA`, improving the accuracy of device and browser identification. ```javascript Sec-CH-UA ``` -------------------------------- ### Extend edit mode with restart command Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Enhances the 'edit' mode by adding a 'restart' command, allowing for easier server restarts during development. ```javascript restart ``` -------------------------------- ### Add support for multiple events Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Enables support for listening to multiple events simultaneously using the `ON('event1 + event2 + event3', function() {})` syntax. ```javascript ON('event1 + event2 + event3', function() {}) ``` -------------------------------- ### Add REQUEST opt.writer option Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Enhances the REQUEST function by introducing the `opt.writer` option, which accepts a function to handle the response. This provides a way to customize response processing. ```javascript REQUEST() opt.writer {function(res)} ``` -------------------------------- ### Define Action with Input/Output Schema (JavaScript) Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md This snippet shows how to define a new action using `NEWACTION` in Total.js. It specifies the input schema (`name:String, age:Number`), output schema (`success:Boolean`), parameters, and the route. The action function receives the model, processes it, and sends a success response. ```javascript NEWACTION('Save', { input: '*name:String, age:Number', output: 'success:Boolean', params: 'projectid:String, id:String', route: '+API ?', action: function($, model) { // $.query {Object key:value} // $.user {Object key:value} // $.params {Object key:value} // $.model {Object key:value} or model "is prepared according to the input data schema" // $.headers {Object key:value} // $.ip {String} // $.files {Array} // $.invalid(error_or_http_status) // $.callback({ success: true }); // $.success(data); // $.redirect(url); model.id = UID(); $.success(model.id); } }); ``` -------------------------------- ### Add HTTP auto-redirect for WebSocketClient Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Implements HTTP auto-redirect support for `WebSocketClient`, improving connection stability and handling. ```javascript WebSocketClient ``` -------------------------------- ### Total.js Framework Watcher Addition Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds a watcher for `extensions/*.html` files to monitor changes in HTML extension files. ```javascript - added watcher for `extensions/*.html` files ``` -------------------------------- ### Extend HTMLParser with selector for prefixes Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Extends the `HTMLParser` to support selectors for prefixes, such as `node.find('xsd:')`, enabling more specific element selection. ```javascript node.find('xsd:') ``` -------------------------------- ### Add action.status() and $.status() Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces `action.status(fn)` for handling status within actions and `$.status(value)` for calling status updates. ```javascript action.status(fn) ``` ```javascript $.status(value) ``` -------------------------------- ### RESTBuilderInstance: stream(callback) Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Creates a request and returns the wrapped response stream to a callback function. The callback receives an error and a response object containing the stream, host, headers, and status. Returns the RESTBuilderInstance object for chaining. ```javascript builder.stream(function(err, response) { // response.stream {Response stream} // response.host {String} Resolved host // response.headers {Object} Obtained headers // response.status {Number} HTTP status code }); ``` -------------------------------- ### WebSocketController Hostname Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the missing `$.hostname()` method to the WebSocketController for retrieving the host's network name. ```javascript added missing `$.hostname()` method in the `WebSocketController` ``` -------------------------------- ### HTML and CSS for Total.js Framework 5 Layout Source: https://github.com/totaljs/framework5/blob/main/error.html This snippet defines the fundamental HTML structure and CSS styling for a Total.js Framework 5 application. It includes styles for the overall page layout, table-based elements, responsive design adjustments, and a keyframe animation for visual effects. The CSS is designed to ensure a consistent and appealing user interface across different devices. ```HTML Total.js Framework 5 ``` ```CSS html,body { height: 100%; width: 100%; overflow: hidden; font-family: Arial; font-smoothing:antialiased; background-color: white; margin: 0; padding: 0; color: black; } .table { display: table; width: 100%; height: 100%; table-layout: fixed; } .body { padding: 20px; } .cell { display: table-cell; vertical-align: middle; text-align: center; width: 100%; height: 100%; font-size: 30px; } .cell b { font-size: 60px; background-color: #000; border-bottom: 5px solid #D0D0D0; color: #FFF; position: relative; display: inline-block; padding: 10px 15px; border-radius: 10px; margin-bottom: 20px; animation: anim 0.5s forwards 2s; } .error { font-size: 11px; color: gray; width: 90%; max-width: 800px; margin: 20px auto; background-color: #F0F0F0; padding: 10px; border-radius: 2px; text-align: left; font-family: monospace; overflow: auto; } #url { font-size: 12px; color: gray; margin: 5px 0; } @keyframes anim { 0% { transform: rotate(0deg); } 50% { transform: rotate(-3deg) scale(1.3); } 100% { transform: rotate(5deg) scale(1); } } @media(max-width: 768px) { .cell b { margin-bottom: 10px; } .cell { font-size: 25px; } } ``` -------------------------------- ### API Pipe Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the API.pipe() method as an alias for API.callback(), offering a consistent way to manage callbacks across different modules. ```javascript added `API.pipe()` method as alias to `API.callback()` ``` -------------------------------- ### Create Todo Task Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md Creates a new todo task with a unique identifier and timestamp. It inserts the task data into the 'tbl_todo' database table and returns the newly created task's ID. User authentication is recommended for this action. ```javascript NEWACTION('Todo|create', { name: 'Create task', input: '*name:String, *body:String', route: '+API ?', action: async function($, model) { model.id = UID(); model.dtcreated = new Date(); model.createdby = $.user ? $.user.name : null; await DATA.insert('tbl_todo', model).promise($); $.success(model.id); } }); ``` -------------------------------- ### QueryBuilder User ID Support Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Enhances the `QueryBuilder.userid()` method to support `$` options and controller instances. This allows for more flexible and dynamic querying based on user IDs, potentially incorporating controller-specific context or configuration. ```javascript QueryBuilder.userid('someUserId', { $option: true }); QueryBuilder.userid(controller.user.id); ``` -------------------------------- ### RESTBuilder Pipe Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the RESTBuilder.pipe() method as an alias for RESTBuilder.callback(), providing a unified approach to handling callbacks in REST operations. ```javascript added `RESTBuilder.pipe()` method as alias to `RESTBuilder.callback()` ``` -------------------------------- ### Improve $.callback() Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Improves the `$.callback()` method to accept another instance of `$`, allowing for more flexible callback chaining. ```javascript $.callback() ``` -------------------------------- ### Total.js Framework CONF.$root Proxy Fix Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes the CONF.$root setting in proxies for proper configuration management. ```javascript - fixed `CONF.$root` in proxies ``` -------------------------------- ### File Cache Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the FILECACHE method for managing cached files. It allows specifying an ID, expiration time, a callback function, a maker function, and encoding. ```javascript added `FILECACHE(id, expire, callback, maker, encoding)` method ``` -------------------------------- ### RESTBuilderInstance: callback(callback) Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Specifies a callback function to handle values from the database. The callback receives an error and the response object. Returns the RESTBuilderInstance object for chaining. ```javascript buidler.callback(callback); ``` -------------------------------- ### Total.js Framework Readfile Extension Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Extends the Total.readfile(path, [type]) method by adding a new 'datauri' type for reading files as data URIs. ```javascript - extended `Total.readfile(path, [type])` by adding a new type `datauri` ``` -------------------------------- ### Add $.hostname to SchemaOptions Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the `$.hostname` property (String) to `SchemaOptions`, providing access to the hostname within schema definitions. ```javascript $.hostname {String} ``` -------------------------------- ### Add size argument to WebSocket.on('message') Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds a new `size {Number}` argument to the `WebSocket.on('message', function(client, msg, [size]))` event handler, providing message size information. ```javascript WebSocket.on('message', function(client, msg, [size])) ``` -------------------------------- ### Add Total.remote() for remote editing Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the `Total.remote('wss_totaljs_code_url')` method for remote source-code editing via WebSockets, facilitating live coding and debugging. ```javascript Total.remote('wss_totaljs_code_url') ``` -------------------------------- ### RESTBuilder BASE64 Response Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Details the enhancement to the RESTBuilder's `?.base64()` method, which enables the retrieval of responses in BASE64 format. ```javascript added `RESTBuilder.?.base64()` method which returns the response in BASE64 format ``` -------------------------------- ### Total.js Framework Static File Loading Improvement Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Improves the loading of static files, particularly in release mode, for better performance. ```javascript - improved loading static files in release mode ``` -------------------------------- ### Add NEWCOMPONENT method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the `NEWCOMPONENT(html_or_URL_or_name, [callback])` method for compiling FlowStream components from HTML, URLs, or names. ```javascript NEWCOMPONENT(html_or_URL_or_name, [callback]) ``` -------------------------------- ### Total.js Framework User-Agent Parser Improvement Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Improves the user-agent parser for more accurate identification of client devices and browsers. ```javascript - improved user-agent parser ``` -------------------------------- ### QueryBuilder Schema Support Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Highlights the added support for schemas in the QueryBuilder.autoquery() method, allowing queries to be associated with specific schema names. ```javascript added support for schemas in the `QueryBuilder.autoquery(..., '@schema_name')` method ``` -------------------------------- ### Total.js: Read and Search Data Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md This snippet demonstrates how to read data from a table ('tbl_user'), filter by 'isremoved' status, search by 'name', and process the response using a callback function. It utilizes the DATA module for database operations. ```javascript DATA.read('tbl_user').where('isremoved', false).search('name', 'Peter').callback(function(err, response) { // response {Object} console.log(err, response); }); ``` -------------------------------- ### Controller Action Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the `controller.action()` method, likely for defining or managing controller actions within the framework. This method provides a structured way to handle different actions or operations within a controller. ```javascript controller.action('someAction', function() { // Action logic }); ``` -------------------------------- ### View Engine @{version} Property Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Describes the new `@{version}` property in the Total.js View engine, which automatically appends a timestamp to URLs for cache busting. ```javascript added a new view engine property `@{version}` that appends `?ts=start_app_timestamp` ``` -------------------------------- ### Implement Authorization with AUTH Delegate Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md This snippet demonstrates how to use the AUTH delegate function in Total.js to implement an authorization mechanism. It checks for a specific token in the request headers and either authorizes the user with a session object or invalidates the request. ```javascript AUTH(function($) { // This method will be executed for every request except those for static files. // $ {Options} Documentation: https://docs.totaljs.com/total5/IbGpBV25x60f/ // $.url {String} It returns the current relative endpoint. // $.query {Object key:value} It returns the URL query arguments of a request. // $.headers {Object key:value} It returns a request headers. // $.ip {String} It returns a request IP address. // $.invalid(); This is an important method for unauthorized request. // $.success(user_session); This is an important method for authorizing request. // $.cookie(name); This method returns a cookie value. if ($.headers['x-token'] === '123456') { // Here, you can load the user session from a database, for example. $.success({ name: 'Token', sa: true }); } else $.invalid(); }); ``` -------------------------------- ### Add test functionality for Flow components Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces a test functionality specifically for testing Flow components, aiding in quality assurance. ```javascript Flow components ``` -------------------------------- ### Add opt.retry() to API evaluation Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the `opt.retry()` method within the API evaluation context, allowing for automatic retries on API calls that fail. ```javascript API opt.retry() ``` -------------------------------- ### Add WebSocket redirections support Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for WebSocket redirections in the remote edit functionality, enhancing the remote development experience. ```javascript remote edit ``` -------------------------------- ### NEWACTION Declaration Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md Declares a new action with a given ID and optional configuration. Actions are fundamental building blocks for handling requests and executing logic in the Total.js framework. ```javascript NEWACTION(id, opt); ``` -------------------------------- ### Total.js Framework Linking Errors Fix Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Resolves linking errors related to resource files, ensuring proper asset inclusion. ```javascript - fixed linking errors with the resource files ``` -------------------------------- ### RESTBuilderInstance: promise($) Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Returns a promise instead of using a callback, which is useful for handling errors in NEWACTION. An optional options object can be provided. Returns the RESTBuilderInstance object for chaining. ```javascript buidler.promise($); ``` -------------------------------- ### FILESTORAGE Copy Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes the FILESTORAGE().copy(id, newid, [callback]) method for reliable file copying operations. ```javascript fixed `FILESTORAGE().copy(id, newid, [callback])` method ``` -------------------------------- ### New Events in Total.js Framework Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for new events within the framework, allowing for more granular control over application lifecycle and requests. These events include 'request', 'controller', and 'websocket'. ```javascript ON('request', function(req, res, flags) { // Handle request event }); ON('controller', function(controller) { // Handle controller event }); ON('websocket', function(ws) { // Handle websocket event }); ``` -------------------------------- ### QueryBuilder Gridfilter Enhancement Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Explains the extension of the QueryBuilder.gridfilter() method to support exact value matching, including single values or multiple comma-separated values. ```javascript extended `QueryBuilder.gridfilter()` by adding `=EXACT_VALUE` or `=EXACT_VALUE1,EXACT_VALUE2` ``` -------------------------------- ### Extend PROXY with custom handler Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Extends the PROXY function to support a custom handler for stream processing. This allows for more flexible control over how data streams are managed. ```javascript PROXY(endpoint, stream_function(ctrl)) ``` -------------------------------- ### Inline Schema Inheritance in Forms Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for inheriting inline schemas in forms, using a syntax like `id:String,@address,@products`. This feature simplifies form definition by allowing reuse of schema definitions and referencing related schemas. ```javascript schema.field('id', 'String'); schema.field('address', '@address'); schema.field('products', '@products'); ``` -------------------------------- ### Add TotalAPI() method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the missing `TotalAPI()` method to the framework, likely for interacting with Total.js API functionalities. ```javascript TotalAPI() ``` -------------------------------- ### NEWACTION Cache Extension Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Details the extension of the NEWACTION cache to include an additional 'input' key for more comprehensive caching strategies. ```javascript extended `NEWACTION` cache with additional `input` key ``` -------------------------------- ### QueryBuilder Callback Handling Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Specifies a callback function for handling query results, receiving error and response arguments. ```javascript buidler.callback(callback); // This is a callback for handling values from the database. // callback {Function(err, response)} a callback function. // returns {QueryBuilder} object; ``` -------------------------------- ### RESTBuilderInstance: file(name, filename, [buffer]) Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Modifies payload serialization for 'multipart/form-data' requests, adding a file. Requires a name for the file data, a filename, and optionally a buffer containing the file content. Returns the RESTBuilderInstance object for chaining. ```javascript builder.file(name, filename, [buffer]); ``` -------------------------------- ### Add F.extend() for extending prototypes Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the `F.extend(prototype, name, fn)` method for extending Total.js prototypes with new properties and functions. ```javascript F.extend(prototype, name, fn) ``` -------------------------------- ### Audit Logs for Actions Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the capability to automatically generate audit logs for Actions, allowing for dynamic logging of execution details like 'Executed by {{ $.user.name }}'. ```javascript added auto audit logs to Actions in the form: `NEWACTION({ ... audit: 'Executed by {{ $.user.name }}' })` ``` -------------------------------- ### Total.js Framework NEWACTION Extend Option Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the 'extend:String' option to the NEWACTION() method, allowing for extended configurations. ```javascript - added `extend:String` option in `NEWACTION()` method ``` -------------------------------- ### Localization Support in TEMPLATE Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for localization within the TEMPLATE() method, enabling the creation of multi-language templates. ```javascript added support for localization in the `TEMPLATE()` method ``` -------------------------------- ### QueryBuilder Promise Handling Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Returns a promise for handling query results asynchronously, useful for error management. ```javascript builder.promise($); // It returns a promise instead of a callback. // $ {Options} optional, it's very helpful for handling errors in "NEWACTION". // returns {QueryBuilder} object; ``` -------------------------------- ### Total.js Framework String.toName Method Fix Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes the String.toName() method to correctly handle and remove multiple spaces. ```javascript - fixed removing of multiple spaces in the `String.toName()` method ``` -------------------------------- ### Controller Authorization Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the `controller.authorize([callback])` method for securing controller actions. It allows for custom authorization logic to be implemented via a callback function, ensuring that only authorized users or requests can access specific controller functionalities. The improved version automatically assigns `controller.user`. ```javascript controller.authorize(function(req, res, callback) { // Custom authorization logic callback(null, true); // Allow access }); // Improved version automatically assigns controller.user controller.authorize(); ``` -------------------------------- ### Read Specific Todo Task Source: https://github.com/totaljs/framework5/blob/main/docs/actions.md Reads a specific todo task from the 'tbl_todo' database table using its unique ID. If the task is not found, it returns a 404 error. The action is protected by authentication. ```javascript NEWACTION('Todo|read', { name: 'Read a specific task', input: '*id:UID', route: '+API ?', action: async function($, model) { let response = await DATA.read('tbl_todo').id(model.id).error(404).promise($); $.callback(response); } }); ``` -------------------------------- ### Total.js Framework User-Agent Parsing Fix Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes the parsing of user-agent strings for more accurate client information. ```javascript - fixed parsing `user-agent` ``` -------------------------------- ### Total.syslog Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds the Total.syslog(msg) method for internal application logging, facilitating debugging and monitoring. ```javascript added `Total.syslog(msg)` method for internal app logging ``` -------------------------------- ### Total.js Framework $.action Properties Fix Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes the assignment of 'user', 'query', and 'params' properties in the $.action() method for accurate data association. ```javascript - fixed assigning `user`, `query` and `params` properties in the `$.action()` method ``` -------------------------------- ### Total.js: RESTBuilder API Request Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Creates an HTTP POST request conforming to Total.js API specifications. It requires an absolute URL, an action name, and an optional payload, which defaults to JSON serialization. ```javascript RESTBuilder.API(url, action, [payload]); ``` -------------------------------- ### Add middleware support for actions Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Adds support for middleware in actions, allowing for the interception and modification of action execution pipelines. ```javascript actions ``` -------------------------------- ### Fix Image.measureWEBP() bug Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Fixes a bug in the `Image.measureWEBP()` method related to image measurement, ensuring accurate results for WEBP images. ```javascript Image.measureWEBP() ``` -------------------------------- ### RESTBuilderInstance: insecure() Source: https://github.com/totaljs/framework5/blob/main/docs/globals.md Allows insecure connections for invalid SSL certificates. Returns the RESTBuilderInstance object for chaining. ```javascript builder.insecure(); ``` -------------------------------- ### ErrorBuilder Throw Method Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Introduces the ErrorBuilder.throw() method, which facilitates the throwing of errors when an error is added to the ErrorBuilder. ```javascript added `ErrorBuilder.throw()` method which throws an error when an error is pushed ``` -------------------------------- ### HTMLParser XML Support Source: https://github.com/totaljs/framework5/blob/main/changelog.txt Enhances the HTMLParser to support XML parsing, including handling of CDATA sections. ```javascript fixed HTMLParser for XML, added support for `