<commit_before>// vim: sw=4:ts=4:nu:nospell:fdc=4
/*
 *  Copyright 2014 <NAME> Cancer Research Center
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

Ext.namespace("LABKEY.ext");

LABKEY.ext.ActiveModules = Ext.extend(Ext.Panel, {
  constructor: function (config) {
    var cntMain = new Ext.Container({
      autoHeight: true,
      html: "<div class='placeholder' style='height: 40px;'></div>",
      layout: "form",
      listeners: {
        afterrender: {
          fn: function () {
            var myMask = new Ext.LoadMask(cntMain.getEl(), {
              msg: "Please, wait, while the list of active modules is loading",
              msgCls: "mask-loading",
            });

            var onFailure = function (a, b, c) {
              myMask.hide();
              LABKEY.ext.ISCore.onFailure(a, b, c);
            };

            var generateActiveModules = function () {
              var modules = [
                "GeneExpressionExplorer",
                "GeneSetEnrichmentAnalysis",
                "ImmuneResponsePredictor",
                "DimensionReduction",
                "DataExplorer",
              ];
              if (!LABKEY.ext.ISCore.isStudyFolder) {
                modules.pop();
              }
              var filters = [
                LABKEY.Filter.create(
                  "Name",
                  LABKEY.container.activeModules.join(";"),
                  LABKEY.Filter.Types.IN
                ),
                LABKEY.Filter.create(
                  "Name",
                  modules.join(";"),
                  LABKEY.Filter.Types.IN
                ),
              ];

              LABKEY.Query.selectRows({
                columns: ["Name", "Label", "Description"],
                failure: onFailure,
                filterArray: filters,
                queryName: "modules",
                schemaName: "core",
                success: function (d) {
                  myMask.hide();

                  if (d.rows.length == 0) {
                    cntMain
                      .getEl()
                      .mask(
                        "There are no active modules enabled in this study.",
                        "infoMask"
                      );
                  } else {
                    cntMain.update("");

                    Ext.each(d.rows, function (e) {
                      if (!LABKEY.ext.ISCore.isStudyFolder) {
                        LABKEY.Ajax.request({
                          method: "GET",
                          url: LABKEY.ActionURL.buildURL(
                            "immport",
                            "containersformodule.api",
                            null,
                            {
                              name: e.Name,
                            }
                          ),
                          failure: onFailure,
                          success: function (request) {
                            var data = JSON.parse(request.response),
                              studies = Ext.pluck(data.result, "name"),
                              linkedStudies = [];
                            studies = studies.filter(function (study) {
                              if (
                                study === "Studies" ||
                                study === "SDY_template"
                              ) {
                                return false;
                              } else {
                                return true;
                              }
                            });
                            studies.sort(function (a, b) {
                              a = a.replace("SDY", "");
                              b = b.replace("SDY", "");
                              return Number(a) - Number(b);
                            });

                            // the studies have been filtered by the Container Filters API
                            // https://www.notion.so/rglab/Data-Finder-Developer-Guide-d4a90cd38aff407b8d624f350963080b#6d98ca08f9744b97b9570a398f05eb94
                            LABKEY.Query.selectRows({
                              schemaName: "study",
                              queryName: "Study",
                              success: (data) => {
                                // filteredStudies will be a list of study names that passed the DataFinder filters
                                let filteredStudies = [];
                                if (
                                  data != undefined &&
                                  data.rows != undefined
                                ) {
                                  filteredStudies = data.rows.map((study) => {
                                    return study["Label"];
                                  });
                                }

                                // filter out studies for a module that do not match the DataFinder filters
                                const displayStudies = studies.filter((study) =>
                                  filteredStudies.includes(study)
                                );

                                displayStudies.forEach(function (study) {
                                  linkedStudies.push(
                                    "<a href='" +
                                      LABKEY.ActionURL.buildURL(
                                        e.Name,
                                        "begin",
                                        LABKEY.ActionURL.getContainer() +
                                          "/" +
                                          study
                                      ) +
                                      "'>" +
                                      study +
                                      "</a>"
                                  );
                                });
                                $(".studies-" + e.Name).html(
                                  linkedStudies.length +
                                    " available studies:</br>" +
                                    linkedStudies.join(", ")
                                );
                              },
                            });
                          },
                        });
                      }
                      cntMain.add(
                        new Ext.Container({
                          html:
                            "<div>" +
                            "<div class='bold-text'><a href=\"" +
                            LABKEY.ActionURL.buildURL(e.Name, "begin") +
                            '">' +
                            e.Label +
                            "</a></div>" +
                            (e.Description == null
                              ? ""
                              : LABKEY.ext.ISCore.isStudyFolder
                              ? "<div class='padding5px'>" +
                                e.Description +
                                "</div>"
                              : "<div style='padding: 5px 5px 0px 5px;'>" +
                                e.Description +
                                "</div>" +
                                "<div class='padding5px studies-" +
                                e.Name +
                                "'></div>") +
                            "</div>",
                          style: "padding-bottom: 5px; padding-top: 5px;",
                        })
                      );
                    });

                    cntMain.doLayout();
                  }
                },
              });
            };

            myMask.show();
            if (!LABKEY.ext.ISCore.isStudyFolder) {
              LABKEY.Ajax.request({
                failure: onFailure,
                method: "GET",
                success: function (request) {
                  var response = JSON.parse(request.response);
                  if (response.data && response.data.containers.length) {
                    generateActiveModules();
                  } else {
                    cntMain.update(
                      "<div class='placeholder' style='height: 40px;'>No data available</div>"
                    );
                  }
                },
                url: LABKEY.ActionURL.buildURL(
                  "study-shared",
                  "getSharedStudyContainerFilter.api"
                ),
              });
            } else {
              generateActiveModules();
            }
          },
          single: true,
        },
      },
    });

    this.border = false;
    this.boxMinWidth = 370;
    this.cls = "ISCore";
    this.frame = false;
    (this.items = cntMain), (this.layout = "fit");
    this.renderTo = config.webPartDivId;
    this.webPartDivId = config.webPartDivId;
    this.width = document.getElementById(config.webPartDivId).offsetWidth;

    LABKEY.ext.ActiveModules.superclass.constructor.apply(this, arguments);
  }, // end constructor
}); // end ActiveModules Panel class
<commit_msg>Add differential expression to active modules for studies<commit_after>// vim: sw=4:ts=4:nu:nospell:fdc=4
/*
 *  Copyright 2014 <NAME> Cancer Research Center
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

Ext.namespace("LABKEY.ext");

LABKEY.ext.ActiveModules = Ext.extend(Ext.Panel, {
  constructor: function (config) {
    var cntMain = new Ext.Container({
      autoHeight: true,
      html: "<div class='placeholder' style='height: 40px;'></div>",
      layout: "form",
      listeners: {
        afterrender: {
          fn: function () {
            var myMask = new Ext.LoadMask(cntMain.getEl(), {
              msg: "Please, wait, while the list of active modules is loading",
              msgCls: "mask-loading",
            });

            var onFailure = function (a, b, c) {
              myMask.hide();
              LABKEY.ext.ISCore.onFailure(a, b, c);
            };

            var generateActiveModules = function () {
              var modules = [
                "GeneExpressionExplorer",
                "GeneSetEnrichmentAnalysis",
                "ImmuneResponsePredictor",
                "DimensionReduction",
                "DifferentialExpressionAnalysis",
                "DataExplorer",
              ];
              if (!LABKEY.ext.ISCore.isStudyFolder) {
                modules.pop();
                modules.pop();
              }
              var filters = [
                LABKEY.Filter.create(
                  "Name",
                  LABKEY.container.activeModules.join(";"),
                  LABKEY.Filter.Types.IN
                ),
                LABKEY.Filter.create(
                  "Name",
                  modules.join(";"),
                  LABKEY.Filter.Types.IN
                ),
              ];

              LABKEY.Query.selectRows({
                columns: ["Name", "Label", "Description"],
                failure: onFailure,
                filterArray: filters,
                queryName: "modules",
                schemaName: "core",
                success: function (d) {
                  myMask.hide();

                  if (d.rows.length == 0) {
                    cntMain
                      .getEl()
                      .mask(
                        "There are no active modules enabled in this study.",
                        "infoMask"
                      );
                  } else {
                    cntMain.update("");

                    Ext.each(d.rows, function (e) {
                      if (!LABKEY.ext.ISCore.isStudyFolder) {
                        LABKEY.Ajax.request({
                          method: "GET",
                          url: LABKEY.ActionURL.buildURL(
                            "immport",
                            "containersformodule.api",
                            null,
                            {
                              name: e.Name,
                            }
                          ),
                          failure: onFailure,
                          success: function (request) {
                            var data = JSON.parse(request.response),
                              studies = Ext.pluck(data.result, "name"),
                              linkedStudies = [];
                            studies = studies.filter(function (study) {
                              if (
                                study === "Studies" ||
                                study === "SDY_template"
                              ) {
                                return false;
                              } else {
                                return true;
                              }
                            });
                            studies.sort(function (a, b) {
                              a = a.replace("SDY", "");
                              b = b.replace("SDY", "");
                              return Number(a) - Number(b);
                            });

                            // the studies have been filtered by the Container Filters API
                            // https://www.notion.so/rglab/Data-Finder-Developer-Guide-d4a90cd38aff407b8d624f350963080b#6d98ca08f9744b97b9570a398f05eb94
                            LABKEY.Query.selectRows({
                              schemaName: "study",
                              queryName: "Study",
                              success: (data) => {
                                // filteredStudies will be a list of study names that passed the DataFinder filters
                                let filteredStudies = [];
                                if (
                                  data != undefined &&
                                  data.rows != undefined
                                ) {
                                  filteredStudies = data.rows.map((study) => {
                                    return study["Label"];
                                  });
                                }

                                // filter out studies for a module that do not match the DataFinder filters
                                const displayStudies = studies.filter((study) =>
                                  filteredStudies.includes(study)
                                );

                                displayStudies.forEach(function (study) {
                                  linkedStudies.push(
                                    "<a href='" +
                                      LABKEY.ActionURL.buildURL(
                                        e.Name,
                                        "begin",
                                        LABKEY.ActionURL.getContainer() +
                                          "/" +
                                          study
                                      ) +
                                      "'>" +
                                      study +
                                      "</a>"
                                  );
                                });
                                $(".studies-" + e.Name).html(
                                  linkedStudies.length +
                                    " available studies:</br>" +
                                    linkedStudies.join(", ")
                                );
                              },
                            });
                          },
                        });
                      }
                      cntMain.add(
                        new Ext.Container({
                          html:
                            "<div>" +
                            "<div class='bold-text'><a href=\"" +
                            LABKEY.ActionURL.buildURL(e.Name, "begin") +
                            '">' +
                            e.Label +
                            "</a></div>" +
                            (e.Description == null
                              ? ""
                              : LABKEY.ext.ISCore.isStudyFolder
                              ? "<div class='padding5px'>" +
                                e.Description +
                                "</div>"
                              : "<div style='padding: 5px 5px 0px 5px;'>" +
                                e.Description +
                                "</div>" +
                                "<div class='padding5px studies-" +
                                e.Name +
                                "'></div>") +
                            "</div>",
                          style: "padding-bottom: 5px; padding-top: 5px;",
                        })
                      );
                    });

                    cntMain.doLayout();
                  }
                },
              });
            };

            myMask.show();
            if (!LABKEY.ext.ISCore.isStudyFolder) {
              LABKEY.Ajax.request({
                failure: onFailure,
                method: "GET",
                success: function (request) {
                  var response = JSON.parse(request.response);
                  if (response.data && response.data.containers.length) {
                    generateActiveModules();
                  } else {
                    cntMain.update(
                      "<div class='placeholder' style='height: 40px;'>No data available</div>"
                    );
                  }
                },
                url: LABKEY.ActionURL.buildURL(
                  "study-shared",
                  "getSharedStudyContainerFilter.api"
                ),
              });
            } else {
              generateActiveModules();
            }
          },
          single: true,
        },
      },
    });

    this.border = false;
    this.boxMinWidth = 370;
    this.cls = "ISCore";
    this.frame = false;
    (this.items = cntMain), (this.layout = "fit");
    this.renderTo = config.webPartDivId;
    this.webPartDivId = config.webPartDivId;
    this.width = document.getElementById(config.webPartDivId).offsetWidth;

    LABKEY.ext.ActiveModules.superclass.constructor.apply(this, arguments);
  }, // end constructor
}); // end ActiveModules Panel class

{'fraction_non_alphanumeric': 0.09383600768551696, 'fraction_numerical': 0.007270083605961469, 'mean_word_length': 0.7996448930006541, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7200935', 'n_tokens_mistral': 4423, 'n_tokens_neox': 4067, 'n_words': 851}