Files
Unify/framework/client/processManager/processManager.update.js
2025-12-25 11:16:59 +01:00

170 lines
3.3 KiB
JavaScript

/*
Copyright (c) 2020, 2023, The Unified Company.
This code is part of Unify.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE,
as published by the Free Software Foundation.
See the GNU AFFERO GENERAL PUBLIC LICENSE, for more details.
https://unifyjs.org
*/
import unify from '../../unify/unify.js';
export default class processManagerUpdate{
process( message ) {
var object = message.data;
var className = tools.getClassNameByObject( object );
console.log("--------------------- recieved message: " + className + " : "+ message.type +"---------------------");
switch( className ) {
case "collection":
this.parseCollection( message );
break;
default:
this.parseObject( message );
}
console.log("--------------------- /recieved message: " + className + " ----------------------");
}
filter( objects ) {
var objectCollection = new collection();
objectCollection.set( this.core.objects );
objectCollection.filter( "type", "renderCollection" );
objectCollection.filter( "custom", function( object ){
var collection = object.getCollection();
if( collection.applicationPathString == applicationPathString ) {
return true;
}
});
return objectCollection.rows;
}
fetchRenderCollections( renderCollections ) {
for( var c = 0; c < renderCollections.length; c++ ) {
var renderCollection = renderCollections[c];
console.log( "renderCollection", renderCollection );
renderCollection.clear();
renderCollection.fetch();
}
}
logRenderCollection( message, objectCollection ) {
console.log( "parse collection", message );
console.log( "search renderCollection", objectCollection );
}
parseCollection( message ) {
var applicationPath = message.applicationPath;
//var objectCollection = this.core.getObjectByPath( applicationPath );
var collectionName = applicationPath[ 0 ];
var applicationPathString = applicationPath.join("/");
var renderCollections = this.filter( this.core.objects );
this.fetchRenderCollections( renderCollections );
this.logRenderCollection( message, objectCollection );
}
getObject( message ) {
var entry = tools.parseObject( message.data );
var className = tools.getClassNameByEntry( entry );
var object = tools.getObjectByEntry( entry );
unify.extend( object );
return object;
}
callMethod( application, eventName, object ) {
application[ "server" + tools.CamelCase( eventName ) ]( object );
}
filterApplication( objects, className, id ) {
var objectCollection = new collection();
objectCollection.set( objects );
objectCollection.filter( "class", className );
objectCollection.filter( "id", id );
var application = objectCollection.getFirstRow();
return application;
}
parseObject( message ) {
var object = this.getObject( message );
// Can be optimized client->core
var className = object.getClassName();
var id = object.id;
var eventName = message.eventName;
this.filterApplication( this.core.objects, className, id )
application.serialize( object );
this.callMethod( application, eventName, object );
this.logRecieveMessage( message );
}
}