1. Application catalogue - solution

    Article: AN0002470Updated: 30.11.2021

    We are showing particular settings and scripts for the described solution in this article.

    First, we will, however, look at the communication scheme of particular objects in the solution.

    Application catalogue and CMDB – communication of ObjectGears objects

    Webpart Script on page Application catalogue

    Tab script

    function OnPreRender()
    {
        //create instance for keeping the text
        var script = '<div class="og-apps"></div><div></div>';

        //add to page
        OGForm.AddControl(OGForm.CreateLiteralControl('lc1', script));
    }

    Tab Styles

    Url to file with styles: modules/OG.AppCatalogue/app-catalogue6.css

    Tab JavaScript

    Url to file with JavaScript: modules/OG.AppCatalogue/app-catalogue-demo2-7.js

    We will copy above stated files to the web folder ./Modules/OG.AppCatalogue/

    Script call

    We will create object Script for execution in the model which contains the page with Application catalogue. We will set a code app-cat and property Script to it:

    //#block app-cat

    OGResponseContent.ContentText = GetData(OGModel);
    OGResponseContent.FileName = 'data.json';

    The Script for execution will call a Script block and take over from it data in json format to display in the application catalogue.

    Script block

    We will create object Script block in the model which contains the page with Application catalogue. We will set a code app-cat and property Script to it:

    var cacheKey = 'og-app-cat';

    function GetData(model) {
      var showKonfPol = OG.Person.IsUserInRoleByCode('it-architect');

      var data = System.Web.HttpContext.Current.Cache.Get(cacheKey);
      var cl = model.ClassDefs['business-application'];
      var ciCl = model.ClassDefs['ci'];

      if (OG.IsNull(data)) {
        //read data
        var f = OG.DataRow.GetDataRowFilter(cl.Id);
        f['display_on_intranet'] = true;
        f.Filter_Sort = 'col' + cl.Columns['application_group'].Id + 'T, col' + cl.Columns['name'].Id;

        OG.DataRow.PrepareFilterForOptimizeRead(f);
        f.PropertiesLoad.Audit = false;
        f.PropertiesLoad.ParentShortDescription = false;

        f.PropertiesLoad.ColumnIds.Add(cl.Columns['is-module-of'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['name'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['description'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['guarantor'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['application_url'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['keyusers'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['icon'].Id);
        f.PropertiesLoad.ColumnIds.Add(cl.Columns['application_group'].Id);
        var sb = new System.Text.StringBuilder(100000);

        var drl = OG.DataRow.GetDataByFilter(f);
        if (drl != null && drl.Count > 0) {
          var sep = '"applications": [';

          for (var i = 0; i < drl.Count; ++i) {
            var dr = drl[i];
            var parentId = dr['is-module-of'] == null ? 0 : dr['is-module-of'];
            var ag = dr['application_group'] == null ? '' : dr.GetColumnDataAsString2('application_group');
            var rn = '';
            var license = '';
            var keyUsers = OG.TextUtils.ConvertEntitiesToSeparatedString(dr['keyusers'], ', ', '');
            var icon = JsonTrimText(dr['icon']);
            if (OG.IsNull(icon)) {
              icon = '';
            }

            sb.Append(sep + '{ "id":"' + dr.Id +
              '","ciId":"' + dr.RemapId(ciCl.Id) +
              '","n":"' + JsonTrimText(dr['name']) +
              '","d":"' + JsonTrimText(dr['description']) +
              '","pId":"' + parentId +
              '","ag":"' + JsonTrimText(ag) +
              '","r":"' + JsonTrimText(rn) +
              '","l":"' + JsonTrimText(license) +
              '","u":"' + JsonTrimText(keyUsers) +
              '","g":"' + JsonTrimText(dr['guarantor']) +
              '","au":"' + JsonTrimText(dr['application_url']) +
              '","i":"' + icon +
              '"'
            );

            sb.Append('}');
            sep = ',';
          }
          sb.Append(']');
        }

        data = sb.ToString();
        System.Web.HttpContext.Current.Cache.Remove(cacheKey);
        System.Web.HttpContext.Current.Cache.Add(cacheKey, data, null, OG.DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration,
            System.Web.Caching.CacheItemPriority.Normal, null);
      }

      return '{"buss_app_id":"' + cl.Id + '", "showKonfPol":"' + (showKonfPol ? 'Y' : 'N') + '",' + data + '}';
    }

    function JsonTrimText(text) {
      if (OG.IsNull(text)) {
        return text;
      }

      var s = replaceAll(text, "\\", "\\\\");
      s = replaceAll(s, "{", " ");
      s = replaceAll(s, "}", " ");
      s = replaceAll(s, "\"", "'");
      s = replaceAll(s, "\n", "<br>");
      s = replaceAll(s, "\r", "");
      return s;
    }

    function replaceAll(string, search, replace) {
      return string.split(search).join(replace);
    }

    function ClearCache()
    {
      System.Web.HttpContext.Current.Cache.Remove(cacheKey);
    }

    The Script will read the data from cache or from the database if the cache is empty, and return the data in json format. The Scrit block also contains a function to clear the cache, which will be called by the rules below.

    In order to optimize size of the transmitted data, space characters were removed from the data and names were shortened to 1-2 characters. This decreased the size of data in our implementation from 110kB to 80kB.

    Rules in the class with applications

    We will create three rules of type Script executed after creation of a new record in the class, modification of the record and after deletion of the record in the class with applications. In all these case we will clear the cache, in order the application reads the data again. Script in the rule calls a function in the Script block, which will perform cache clearance.

    //#block app-cat

    ClearCache();

×