Skip to content

Instantly share code, notes, and snippets.

@mustakim
Last active August 21, 2022 04:19
Show Gist options
  • Save mustakim/fd2ae1537e3b8ddb2f58a9364ffacccc to your computer and use it in GitHub Desktop.
Save mustakim/fd2ae1537e3b8ddb2f58a9364ffacccc to your computer and use it in GitHub Desktop.
tesenso wiki

Code Snippet for state change with relational data


var entitySubType;
var $injector = widgetContext.$scope.$injector;
let customDialog = $injector.get(widgetContext.servicesMap
    .get('customDialog'));
let entityService = $injector.get(widgetContext.servicesMap
    .get('entityService'));
let assetService = $injector.get(widgetContext.servicesMap
    .get('assetService'));
let deviceService = $injector.get(widgetContext.servicesMap
    .get('deviceService'));
let attributeService = $injector.get(widgetContext
    .servicesMap.get('attributeService'));
let entityRelationService = $injector.get(widgetContext
    .servicesMap.get('entityRelationService'));
let dashboardData = '';

$injector.get(widgetContext.servicesMap.get(
        'entityService')).getEntity(entityId.entityType,
        entityId.id)
    .subscribe(function(data) {
        entitySubType = data.type
        let currentUrl = widgetContext.dashboardService
            .currentUrl;
        var dashboardId = '';
        console.log('currentUrl', currentUrl)
        if (currentUrl && currentUrl.trim()) {
            var splitedURL = currentUrl.split('/');
            dashboardId = splitedURL[splitedURL.length - 1];
        }
        $injector.get(
                widgetContext
                .servicesMap.get('dashboardService'))
            .getDashboard(dashboardId)
            .subscribe(function(data) {
                dashboardData = data;
                console.log('dashboardService',
                    data)
                    
                var aliasObject = findObjectInfoByAlias(dashboardData.configuration
                    .entityAliases, 'truck-by-site');
                
                console.log('aliasObject', aliasObject);

                dashboardData.configuration
                    .entityAliases[
                        aliasObject.key
                    ].filter.rootEntity.id =
                    entityId.id;

                console.log('changedDashboard',
                    dashboardData);
                
                $injector.get(
                        widgetContext
                        .servicesMap.get(
                            'dashboardService'))
                    .saveDashboard(dashboardData)
                    .subscribe(() => {
                        // refeshing page
                        $injector.get(
                                widgetContext
                                .servicesMap
                                .get(
                                    'dashboardService'
                                    ))
                            .updateURL(
                                dashboardId);
                    });


            });

        updateDashboardStates('site_state');
    });


function updateDashboardStates(statedId) {
    widgetContext.rxjs.forkJoin([
        entityRelationService
        .findInfoByFrom(
            entityId),
        entityRelationService.findInfoByTo(
            entityId),
        attributeService
        .getEntityAttributes(
            entityId, 'SERVER_SCOPE'),
        entityService.getEntity(entityId
            .entityType,
            entityId.id)
    ]).subscribe((entityInfo) => {
        var stateParams = widgetContext
            .stateController
            .getStateParams();

        // getting information for customization
        console.log('entityInfo ========>',
            entityInfo);

        var entityRelations = [];

        if (entityInfo[0] && entityInfo[0]
            .length >
            0) {
            entityInfo[0].forEach((
                data) => {
                entityRelations
                    .push(data
                        .to);
            })
            console.log('entityRelations',
                entityRelations)
        }

        stateParams = {
            entityId: entityId,
            entityName: entityName,
            entityLabel: entityLabel,
            attributes: {
                status: entityRelations,
                trucks: entityRelations
            }
        };

        var stateNameFromEntity = entityName
            .replace(/\s+/g, '_')
            .toLowerCase();

        console.log('stateParams ========>',
            stateParams);

        // widgetContext.stateController.openState(
        //     stateNameFromEntity,
        //     stateParams);

        // widgetContext.stateController.pushAndOpenState([stateNameFromEntity]);

        widgetContext.stateController
            .updateState(
                '',
                stateParams);
    });
}

function findObjectInfoByAlias(obj, aliasName) {
  for (let [index, [key, value]] of Object.entries(Object.entries(obj))) {
    if (value.alias === aliasName) {
      return {
        index: index,
        key: key,
        value: value
      };
    }
  }
}

Group Feature

Access for Tesenso IOT Solution

All kinds of group

  1. User groups
  2. Customer groups
  3. Asset groups
  4. Device groups
  5. Entity view groups
  6. Edge groups
  7. Dashboard groups

Group Generic Configs

  1. CREATE_GROUP Config
{
    "additionalInfo": {"description": "string"}
    "description": "string"
    "name": "string"
    "type": "EnumGroupType"
}
  1. GET_GROUP Config
{
  "id": {
    "entityType": "ENTITY_GROUP",
    "id": "UUID"
  },
  "createdTime": "Epoch Time",
  "type": "EnumGroupType",
  "name": "string",
  "ownerId": {
    "entityType": "EnumEntityType",
    "id": "UUID"
  },
  "additionalInfo": {
    "description": "string"
  },
  "configuration": {
    "columns": [
      {
        "type": "EnumType",
        "key": "string",
        "sortOrder": "DESC" | "ASC"
      } ...
    ],
    "settings": "object",
    "actions": "object"
  },
  "ownerIds": [
    {
      "entityType": "EnumEntityType",
      "id": "UUID"
    }
  ],
  "edgeGroupAll": "boolean",
  "groupAll": "boolean"
}

Common API Endpoint

  • POST - /entityGroups - CREATE_GROUP - GET_GROUP
  • GET - /entityGroup/{group_id} - GET_GROUP
  • DELETE - /entityGroup/{group_id}

Group API Endpoints

  • GET - /entityGroups/{EnumGroupName} - No Payload - list of GET_GROUP
    • ex: For User Group: /entityGroups/USER

Access for Tesenso IOT Soltion

Dependency for this project

  1. Java
  2. Maven
  3. Postgres
  4. Node

Tesenso IOT Solution

MNL - ThingsBoard UI NGX setup:

Change this in package.json

"float": "^1.0.2", "flot": "github:thingsboard/flot#0.9-work", "flot.curvedlines": "github:MichaelZinsmaier/CurvedLines#master", "ngx-flowchart": "github:thingsboard/ngx-flowchart#release/1.0.0",

URL from user home: Documents\Development\Projects\mnl-thingsboard-rnd

run mvn clean install -DskipTests to the following path

For dev branch (installing one by one with this heirarchy):

  1. server (build completed)
  2. core (build completed)
  3. integration-http (build completed)
  4. rule-engine (build completed)
  5. transport-http (build completed)

run application in intelij

  1. core - for application
  2. integration-http
  3. rule-engine
  4. transport-http
  5. integration-mqtt - for MQTT service

Check this module for learn

  1. User groups
  2. Customer groups
  3. Asset groups
  4. Device groups
  5. Entity view groups
  6. Edge groups
  7. Dashboard groups

==> Generic Role:

  1. Each Role is related to one or more user group
  2. Each user group has only one owner

For Testing MQTT

MQTT Client ID: integration-2bd96ac2-089c-61ee-0564-559e7f9bb12b Username: {"deviceName":"Sample Final device test","deviceType":"Custom Device Profile"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment