Kiss application manager
This module allows to:
- define and access models
- define and access collections
- define views
- define view controllers
- init the application using kiss.app.init()
Once the models and collections are defined, they are stored in the app object.
// Getting models and collections
const appModels = kiss.app.models
const appCollections = kiss.app.collections
// Getting a model definition or a collection
const userModel = appModels.user
const userCollection = appCollections.user
// Using the model
const Bob = userModel.create({firstName: "Bob", lastName: "Wilson"})
await Bob.save()
// Using the collection if you're not sure it's loaded in memory (async method)
const John = await userCollection.findOne("123")
// Using the collection if it's already loaded in memory (sync method)
const Will = userCollection.getRecord("456")
Members
# static collections
Store the application collections. More about collections here.
Example
const userCollection = kiss.app.collections.user
# static models
Store the application models. More about models here.
Example
const userModel = kiss.app.models.user
Methods
# static defineModel(model) → {Model}
Define a new model in the application
This automatically:
- references the model in kiss.app.models
- references a new collection for the model in kiss.app.collections
- references a new record class to instanciate the model
- generates the basic api for the record class (create, save, update, delete)
- generates getters/setters for record's computed fields (= virtual fields)
Check the class Model documentation for more informations about models.
Parameters:
Name | Type | Description |
---|---|---|
model |
object
|
The model configuration object |
The newly defined model
Model
# static defineModelRelationships()
Define the model relationships
This methods explores all the application models and finds automatically the relationships between the models. When exploring the models, specific field types are generating the relationships:
- link: field used to link one or many foreign records
- lookup: field that looks up a field in a foreign record
- summary: field that looks up and summarizes data from multiple foreign records
Example
kiss.app.defineModelRelationships()
# static definePlugin(plugin)
Add a plugin definition to the application
Parameters:
Name | Type | Description |
---|---|---|
plugin |
object
|
# static defineTexts(texts)
Define all the application texts that can be translated. Each text will be used as an English text if it doesn't have any english translation.
Parameters:
Name | Type | Description |
---|---|---|
texts |
object
|
Example
kiss.app.defineTexts({
"hello": {
fr: "bonjour"
},
"#thank": {
en: "thank you",
fr: "merci"
}
})
# static defineView(config)
Define a view by storing its renderer function into the list of view renderers. It does NOT store a view, but instead stores a view 'renderer' function that will generate the view later, when needed.
Parameters:
Name | Type | Description |
---|---|---|
config |
object
|
|
id |
string
|
The id of the view to add |
renderer |
function
|
The function that will render the view when needed |
meta |
object
|
Meta informations injected in the HTML header. Can be localized or not. See examples in kiss.views module. |
Example
kiss.app.defineView({
id: "home",
renderer: function (id, target) {
// ... build your view here
return createPanel({
id, // Very important. Can't work without it.
target, // Optional insertion point in the DOM. You can omit if you don't need it.
title: "My first panel",
// A few panel properties
draggable: true,
closable: true,
width: 300,
height: 200,
boxShadow: "5px 5px 10px #cccccc",
// Panel content
items: [
{
type: "html",
html: "<center>Hello world?</center>",
// W3C events attached to the html element
// It works only if you've attached the "hello" viewController (see below)
events: {
onclick: function() {
$(id).hello()
}
}
}
]
})
}
})
# static defineViewController(id, viewController)
Define a controller for a specific view
The view controller must have the same name as the controlled view. They will be paired automatically.
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
|
viewController |
object
|
Object containing all the controller methods |
Example
// This controller has 4 methods, hello(), world(), foo() and bar()
kiss.app.defineViewController("home", {
hello: function() {
createNotification({
message: "Hello!",
duration: 2000
})
},
// ... or using an arrow function:
world: () => console.log("World!"),
// ... or class member notation:
foo() {
console.log("Foo!")
},
// Methods can be async, too:
async bar() {
return await 42
}
})
# static getCollectionByModelName(modelName) → {object}
Get a Collection by its model's name
Collections are normally retrieved by id like this:
const projectCollection = kiss.app.collections[collectionId]
const projects = await projectCollection.find()
In some situation, we just know the name of the collection's model, so we have to use this method:
const projectCollection = kiss.app.getCollectionByModelName("Project")
const projects = await projectCollection.find()
Parameters:
Name | Type | Description |
---|---|---|
modelName |
string
|
The name of the collection's model (case insensitive) |
Collection
object
# static getModel(modelId) → {object}
Get a Model by id or by name
Note: if the model is not found, the methods tries to find the model by its name
Parameters:
Name | Type | Description |
---|---|---|
modelId |
string
|
id or name (case insensitive) of the model |
Model
object
# static getModelByName(modelName) → {object}
Get a Model by name
Models are normally retrieved by id like this:
const projectModel = kiss.app.models[modelId]
const projectRecord = projectModel.create({projectName: "foo"})
In some situation, we just know the model name and have to use this method:
const projectModel = kiss.app.getModelByName("Project")
const projectRecord = projectModel.create({projectName: "foo"})
Parameters:
Name | Type | Description |
---|---|---|
modelName |
string
|
The name of the model (case insensitive) |
Model
object
# async static init(config)
Init KissJS application
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
object
|
The application configuration object |
|
name |
string
|
<optional> |
Optional application name (will be stored in kiss.app.name) |
logo |
string
|
<optional> |
Optional application logo (will be stored in kiss.app.logo and use in login screens) |
mode |
string
|
<optional> |
"online", "offline", "memory". Default is "online". Don't use "online" for local projects. |
host |
string
|
<optional> |
The host for online requests. Can be localhost in developement. |
https |
boolean
|
<optional> |
Set to false if the application doesn't use https. Default is true. Ignored for "memory" or "offline" modes. |
loginMethods |
Array.<string>
|
<optional> |
The list of login methods to use. Default is ["internal", "google", "microsoft365"] |
startRoute |
string
|
object
|
<optional> |
The route to start with. Can be a string (= viewId) or an object (check router documentation). |
publicRoutes |
Array.<string>
|
<optional> |
The list of public routes which doesn't require authentication |
undoRedo |
object
|
<optional> |
The undo/redo configuration object |
loader |
function
|
<optional> |
The async function used to load your custom resources at startup. Must absolutely return a boolean to indicate success. |
useDirectory |
boolean
|
<optional> |
Set to true if your app uses KissJS directory to manage users, groups and apiClients. Default is false. |
useDynamicModels |
boolean
|
<optional> |
Set to true if your app needs dynamic models. Default is false. |
useFormPlugins |
boolean
|
<optional> |
Set to true if your app needs form plugins. Default is false. |
theme |
object
|
<optional> |
The theme to use. Ex: {color: "light", geometry: "sharp"} |
language |
string
|
<optional> |
"en", "fr" or "es". Default is "en" or the last language used by the user. |
debug |
boolean
|
<optional> |
Enable debug mode if true (default is false) |
Example
await kiss.app.init({
debug: true,
name: "pickaform",
language: "fr",
logo: "./resources/img/logo 256x128.png",
mode: "online",
https: true,
useDirectory: true,
useDynamicModels: true,
useFormPlugins: true,
startRoute: "home-start",
publicRoutes: [
"form-public"
],
undoRedo: {
async undo() {
// Undo code here
},
async redo() {
// Redo code here
}
},
theme: {
color: "light",
geometry: "sharp"
},
loader: async function() {
// Load your resources here
return true // IMPORTANT: return true if everything is loaded correctly, false otherwise
}
})
# static listCollections()
List all the application collections. Give their name and number of records.
# static load() → {boolean}
Load core application data:
- load the directory
- load dynamic models
- define model relationships
- load links between records
- load form plugins
- True if the core application data could be loaded properly, false otherwise
boolean
# static loadDirectory() → {boolean}
Load the application directory (users, groups, apiClients)
- True if the directory is loaded, false otherwise
boolean
# static loadDynamicModels() → {boolean}
Load the dynamic models. Dynamic models are created by the users and have an unpredictable schema.
- True if the dynamic models are loaded, false otherwise
boolean