### Cloning and Initializing Node.js Project (Bash) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/readme.md This snippet provides the necessary bash commands to clone the Node.js database application template, navigate into its directory, set executable permissions for scripts, install dependencies, and configure initial environment and database migration files. ```bash git clone git@github.com:Mrazbb/nodejs-database-app-template.git cd nodejs-database-app-template chmod +x ./scripts/*.sh npm update --save npm install cp .env.main.sample .env.main cp app/sample.altergen.json app/altergen.json chmod +x app/entrypoint.sh ``` -------------------------------- ### Starting the Application with Docker Compose (Bash) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/readme.md This command starts the application's Docker containers in detached mode, as defined by the up script in package.json, bringing all services online. ```bash npm run up ``` -------------------------------- ### Initializing Component and Handling Basic Input Changes (JavaScript) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-input.html This snippet handles initial component setup, including placeholder defaults and autofill logic. It also registers an input and change event listener to trigger a self.check() method, which likely validates or updates the component's state. ```JavaScript if(config.placeholder==0)config.placeholder='0'; if(config.autofill){ if(typeof(config.autofill)==='string'){ config.NAME=config.autofill }else{ var index=self.path.lastIndexOf('.'); config.NAME=index===-1?self.path:self.path.substring(index+1) } } self.aclass(cls+' invisible'); self.rclass('invisible',100); self.redraw(); self.event('input change',function(){ if(nobindcamouflage)nobindcamouflage=false; else self.check() }); ``` -------------------------------- ### Component Setup and Event Handlers (self.make) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-edit.html Sets up the component's DOM structure by appending the edit window and binds global event listeners for `click` (on `.edit`), `dblclick` (on `.edit2`), `keydown`, `blur`, and `paste`. These handlers manage the editing state, apply formatting, and handle navigation (Tab, Enter) and cancellation (Escape). ```JavaScript self.make=function(){self.aclass(cls);self.append('
'.format(cls));floating=self.find(cls2+'-window');$(document).on('click','.edit',self.edit).on('dblclick','.edit2',self.edit);events.keydown=function(e){var t=this;if(!t.$editevents)return;var meta=t.$edit;if(meta.clear){t.innerHTML='';meta.clear=0}if(!meta.keypressed){meta.keypressed=1;$(t).aclass('edit-keypressed')}if((e.metaKey||e.ctrlKey)&&(e.which===66||e.which===76||e.which===73||e.which===85)){if(meta.type!=='html'){e.preventDefault();e.stopPropagation()}}var el;if(e.which===27){el=$(t);t.$edit.is=false;self.detach(el);return}if(e.which===13||e.which===9){if(e.which===13&&meta.multiline)return;e.preventDefault();el=$(t);if(self.approve(el)){self.detach(el);el.rclass('edit-keypressed');if(e.which===9&&self.focusnext(t,e))return}else self.detach(el)}};events.blur=function(){var t=this;if(t.$editevents){var el=$(t);el.rclass('edit-keypressed');t.$edit.is&&self.approve(el);self.detach(el)}};events.paste=function(e){e.preventDefault();e.stopPropagation();var meta=this.$edit,text=e.originalEvent.clipboardData.getData(self.attrd('clipboard')||'text/plain');text&&document.execCommand('insertText',false,meta.multiline?text.trim():text.replace(/\n|\r/g,'').trim())}}; ``` -------------------------------- ### Running Docker Compose Commands via NPM (Bash) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/readme.md These bash commands demonstrate how to use the previously defined NPM scripts to control Docker Compose services, including starting, stopping, restarting, and forcefully killing containers, along with verifying their status. ```bash npm run up # Start containers docker ps # Verify containers npm run down # Stop and remove containers npm run restart # Restart containers npm run stop # Stop containers npm run kill # Forcefully kill containers ``` -------------------------------- ### Initializing Layout Settings and Getting Size Data - JavaScript Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-layout.html This snippet initializes the 'settings' object by executing a string as a function, likely parsing configuration data. It also defines 'getSize', a recursive helper function that retrieves layout dimensions for a given display size (e.g., 'md', 'sm') from the 'data' object, falling back to larger sizes if a specific one isn't found. ```javascript settings=new Function('return '+code)(); !noresize&&self.resize()}; var getSize=function(display,data){ var obj=data[display]; if(obj)return obj; switch(display){ case'md':return getSize('lg',data); case'sm':return getSize('md',data); case'xs':return getSize('sm',data) } return data }; ``` -------------------------------- ### Getting Current DOM Node in JavaScript Editor Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-wysiwyg.html This function, 'self.getNode', retrieves the current DOM node where the selection starts ('anchorNode'). If the node is a text node (nodeType 3), it returns its parent element; otherwise, it returns the node itself, providing the relevant element for formatting checks. ```JavaScript self.getNode=function(){ var node=D.getSelection().anchorNode; if(node)return(node.nodeType===3?node.parentNode:node) }; ``` -------------------------------- ### Initializing Total.js Application with Options - JavaScript Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/docs/documentation.md This snippet initializes a Total.js application, setting various configuration options such as release mode, service mode, and cluster settings. It demonstrates how to configure the application's startup behavior, including IP, port, and temporary directory paths, before running the framework. ```JavaScript // =================================================== // Total.js v5 start script // https://www.totaljs.com // =================================================== require('total5'); const options = {}; // options.ip = '127.0.0.1'; // options.port = parseInt(process.argv[2]); // options.unixsocket = PATH.join(F.tmpdir, 'app_name.socket'); // options.unixsocket777 = true; // options.config = { name: 'Total.js' }; // options.sleep = 3000; // options.inspector = 9229; // options.watch = ['private']; // options.livereload = 'https://yourhostname'; // options.watcher = true; // enables watcher for the release mode only controlled by the app `F.restart()` // options.edit = 'wss://www.yourcodeinstance.com/?id=projectname' options.release = process.argv.includes('--release'); // Service mode: options.servicemode = process.argv.includes('--service') || process.argv.includes('--servicemode'); // options.servicemode = 'definitions,modules,config'; // Cluster: // options.tz = 'utc'; // options.cluster = 'auto'; // options.limit = 10; // max 10. threads (works only with "auto" scaling) F.run(options); ``` -------------------------------- ### Initializing Application Links in Node.js (Commented) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/views/admin.html This commented-out snippet demonstrates a pattern for initial client-side data loading. It uses `CLINIT` to fetch 'pages_links' via `TAPI` and then processes the response using `FUNC.sitemap` before passing it to the next function. This is likely for populating navigation links on application startup. ```JavaScript CLINIT('links', function(next) { TAPI('pages_links', response => next(FUNC.sitemap(response))); }, true); ``` -------------------------------- ### Helper Function for Path Resolution (findfn) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-edit.html Defines a helper function `findfn` used to resolve paths for component properties or global data. It checks if the path starts with '@' to access component-specific properties, otherwise it uses `GET` for global scope resolution, providing flexible data access. ```JavaScript var findfn=function(opt,path){if(path.charAt(0)==='@'){var com=opt.element.component();return com?com[path.substring(1)]:null}else return GET(opt.scope?opt.scope.makepath(path):path)}; ``` -------------------------------- ### Initializing Navigation Editor in Node.js (Commented) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/views/admin.html This commented-out snippet shows a pattern for initial client-side data loading for a navigation editor. It uses `CLINIT` to fetch 'nav_editor' data via `TAPI` and passes the response directly to the next function, suggesting it's for populating an editable navigation structure. ```JavaScript CLINIT('nav', function(next) { TAPI('nav_editor', next); }, true); ``` -------------------------------- ### Injecting API Token and Handling Open Platform in JavaScript Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/views/admin.html An immediately invoked function expression (IIFE) that handles 'openplatform' query parameters, encodes them, and appends them to the API definition. It also sets 'common.ready' to true and removes the 'invisible' class from the body, indicating the application is ready. ```JavaScript (function() { var openplatform = NAV.query.openplatform || ''; ``` -------------------------------- ### Generating TMS Security Token in Total.js Plugin (JavaScript) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/plugins/settings/public/index.html This function generates a new 35-character GUID (Globally Unique Identifier) and sets it as the value for the `secret_tms` field, likely used for a TMS security token. It also triggers a UI update to show the generated token. ```JavaScript exports.generate = function() { exports.set('secret_tms @type:show', GUID(35)); }; ``` -------------------------------- ### Initializing Form in JavaScript UI Component Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-listform.html The `check` function ensures the form element is properly initialized and appended to its container. It's a one-time setup function (`self.$$check` prevents re-execution) that also triggers initial compilation and validation if `config.invalidform` is enabled, setting the form's initial invalid state. ```JavaScript self.check=function(){if(!self.$$check){form=$(form)[0];container.append(form);self.compile&&self.compile();self.$$check=true;self.$$invalid=true;if(config.invalidform)self.validate2()}}; ``` -------------------------------- ### Creating Sample List View with User Details (SQL) Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/docs/documentation.md This SQL view, `public.view_sample_list`, provides a list of sample data records. It enriches the sample data by performing LEFT JOINs with the `tbl_user` table to retrieve the names of the users who created, updated, or removed each sample record, enhancing readability and context. ```SQL CREATE OR REPLACE VIEW "public"."view_sample_list" AS ( SELECT m.id, m.name, m.body, m.countupdate, m.ismobile, -- user m.createdbyid, m.updatedbyid, m.removedbyid, createdby.name AS createdbyname, updatedby.name AS updatedbyname, removedby.name AS removedbyname, m.dtcreated, m.dtupdated, m.dtremoved FROM public.tbl_sample m -- m is for main table LEFT JOIN tbl_user createdby ON createdby.id = m.createdbyid LEFT JOIN tbl_user updatedby ON updatedby.id = m.updatedbyid LEFT JOIN tbl_user removedby ON removedby.id = m.removedbyid ); ``` -------------------------------- ### Building Date Picker HTML - UI Rendering - JavaScript Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-datepicker.html This function begins the process of constructing the HTML structure for the date picker. It initializes an array `builder` and pushes the opening `div` tag for the header, including navigation controls for "next" and "previous" months/years. This snippet is incomplete but shows the start of dynamic HTML generation. ```JavaScript self.makehtml=function(){var builder=[];builder.push('{0}'.format(node===editor[0]?selection:node.innerHTML))}break;case'clean':var selection=self.getSelection();if(selection){node=self.getSelection(true)}else{node=findparent(self.getNode());node&&clean(node)}break;case'link':var node=self.getNode();var tag=check(node,'A');if(tag){clean(tag)}else{var id='#URL'+Date.now();var html=self.getSelection();if(html){D.execCommand('CreateLink',false,id);var a=self.find('a[href="{0}"]').attr('target','_blank').attr('href',html);self.event('link',a)}}break}}).each(function(){buttons[this.name]=this});var el=self.element;el.on('selectstart',function(){clearTimeout(timers.selec}
```
--------------------------------
### Initializing Keyboard Shortcut Component - JavaScript
Source: https://github.com/mrazbb/nodejs-database-app-template/blob/main/app/public/cdn/j-shortcuts.html
This snippet defines the 'shortcuts' component, initializing its internal state variables like 'items', 'keys', and 'keys_session'. It sets up global event listeners for keydown events to capture user input and trigger registered shortcut callbacks. It also registers a listener for 'component + knockknock' events to refresh shortcuts.
```JavaScript
COMPONENT('shortcuts',function(self){var items=[],length=0,keys={},keys_session={},issession=false;self.singleton();self.readonly();self.blind();self.nocompile&&self.nocompile();var cb=function(o,e){o.callback(e,o.owner)};self.make=function(){$(W).on('keydown',function(e){var f=e.key||'',c=e.keyCode;if(f.length>1&&f.charAt(0)==='F')c=0;else f='-';var key=(e.ctrlKey?1:0)+''+(e.altKey?1:0)+''+(e.shiftKey?1:0)+''+(e.metaKey?1:0)+f+c;if(issession){if(!keys_session[key])return}else{if(!keys[key])return}if(length&&!e.isPropagationStopped()){for(var i=0;i