Esempio n. 1
0
        public ActionResult ByFilter(string classifierId)
        {
            SearchBox sb = new SearchBox(Language.Id);

            sb.ClassifierFilter = Guid.Parse(classifierId);

            Language lang       = InterfaceLanguages.GetLanguageById(Convert.ToInt32(Session["LanguageId"]));
            String   languageId = lang.Id.ToString();

            ClassificatorTreeModel treeModel = ClassifiersProvider.Service.GetTreeByGuid(classifierId);

            IEnumerable <ClassificatorModel> flatten = treeModel.FlattenTo();

            bool isCurrentLanguageAvailable = flatten.All(f => f.LanguageVariantsWithHints.ContainsKey(languageId));

            if (!isCurrentLanguageAvailable)
            {
                // Use english by default (Id = 4)
                lang = InterfaceLanguages.GetLanguageById(4);
            }

            String filter = String.Join(" / ", flatten.Select(x => x.LanguageVariantsWithHints[languageId].Title));

            sb.ClassifierFilterTitle = filter;

            return(Search(sb));
        }
Esempio n. 2
0
        public static List <FolderData> GetClassifier(string tab, string classifierType, string parentId, int langId, int productId, bool skipFirstLevel = true)
        {
            var csc = ClassificatorService.Current;

            List <FolderData> fd = new List <FolderData>();

            if (classifierType == "EULegislation")
            {
                classifierType = "DirectoryLegislatioN";
            }
            int classifierTypeId = DB.GetClassifierTypeIdByName(classifierType);

            /*
             * if (classifierTypeId.HasValue)
             * {
             *  foreach (var r in DB.GetClassifier(classifierTypeId.Value, parentId, langId))e
             *  {
             *      Guid id = Guid.Parse(r["id"].ToString());
             *
             *      if (skipFirstLevel && !parentId.HasValue)
             *          return GetClassifier(classifierType, id, langId, skipFirstLevel);
             *
             *      fd.Add(new FolderData()
             *      {
             *          id = id,
             *          key = r["id"].ToString(),
             *          title = r["name"].ToString(),
             *          lazy = true,
             *          folder = false
             *      });
             *  }
             * }*/

            if (String.IsNullOrEmpty(parentId) || parentId == null || parentId == "null")
            {
                parentId = DB.GetClassifierBaseByTypeId(classifierTypeId);
            }

            var treeByParent = ClassifiersProvider.Service.GetTreeByGuid(parentId);

            foreach (var child in treeByParent.Children)
            {
                var curFolderData = new FolderData()
                {
                    id    = new Guid(child.Guid),
                    key   = child.Guid,
                    ord   = (child.Order.HasValue) ? child.Order : -1,
                    title = child.LanguageVariantsWithHints.ContainsKey(langId.ToString()) ? child.LanguageVariantsWithHints[langId.ToString()].Title : child.LanguageVariantsWithHints.Values.FirstOrDefault().Title.ToString(),
                    //tooltip = (child.LanguageVariantsWithHints.ContainsKey(langId.ToString()) && child.LanguageVariantsWithHints[langId.ToString()].Hint != "") ? child.LanguageVariantsWithHints[langId.ToString()].Hint : child.LanguageVariantsWithHints.Values.FirstOrDefault().Hint.ToString(),
                    tooltip    = (child.LanguageVariantsWithHints.ContainsKey(langId.ToString())) ? child.LanguageVariantsWithHints[langId.ToString()].Hint : "",
                    lazy       = (child.Children.Count > 0), // Show/Hide lazy load icon (rectangle) in tree view
                    folder     = false,
                    tree_level = child.TreeLevel
                                 //  docs_count = child.DocumentCount,
                                 //  unselectable = child.DocumentCount == 0 ? true : false,
                                 //  hideCheckbox = child.DocumentCount == 0 ? true : false
                };

                /* if (tab.ToUpper() == "CASES") // ToUpper is faster than ToLower lol..
                 * {
                 *   curFolderData.docs_count = child.DocumentCounts["caselaw"].Count;
                 * }
                 * else if (tab.ToUpper() == "LAW")
                 * {
                 *   curFolderData.docs_count = child.DocumentCounts["legislation"].Count;
                 * }
                 * else if (tab.ToUpper() == "PAL")
                 * {
                 *   curFolderData.docs_count = child.DocumentCounts["legislation"].Count;
                 * }
                 * else // finances and other
                 * {
                 *   curFolderData.docs_count = child.DocumentCounts["any"].Count;
                 * }*/

                if (productId == 1)
                {
                    // Juridiction context
                    if (child.ClassifierTypeId == 7)
                    {
                        // Direct jurisdiction mappings
                        ClassificatorTreeModel mappedClassifier = null;
                        mappedClassifier = csc.MappingService.GenericTryGet(child.Guid.ToString());
                        if (mappedClassifier != null)
                        {
                            // mapping is found
                            curFolderData.docs_count = mappedClassifier.DocumentCounts["eurocases"].Count;
                        }
                        else
                        {
                            // checking childs - no deep-level recursive check for performance, edit this if classifier struct changes
                            var currentClassifierChilds = csc.TryGetTreeByGuid(child.Guid.ToString()).Children;
                            var mappedChilds            = currentClassifierChilds.Select(c => csc.MappingService.GenericTryGet(c.Guid.ToString()));
                            var mappedChildsCount       = 0;
                            if (mappedChilds.Any(c => c != null))
                            {
                                mappedChildsCount = mappedChilds.Sum(c => c.DocumentCounts["eurocases"].Count);
                            }

                            curFolderData.docs_count = mappedChildsCount;
                        }
                    }
                    else
                    {
                        curFolderData.docs_count = child.DocumentCounts["eurocases"].Count;
                    }
                }
                else if (productId == 2)
                {
                    curFolderData.docs_count = child.DocumentCounts["tfs"].Count;
                }

                var isDocsCountZero = curFolderData.docs_count == 0;

                curFolderData.unselectable = isDocsCountZero;
                curFolderData.hideCheckbox = isDocsCountZero;

                if (productId == 1 || (productId == 2 && isDocsCountZero == false))
                {
                    fd.Add(curFolderData);
                }
            }

            return(fd);
        }
        private static List <ClassificatorTreeModel> GetClassifiersFromDatabase()
        {
            int deepestLevel = DB.GetClassifiersDeepestLevel();
            var dic          = new Dictionary <string, ClassificatorTreeModel>();

            for (int i = 1; i <= deepestLevel; i++)
            {
                var classifiersFromDB = DB.GetClassifiersByTreeLevel(i);

                foreach (var classifier in classifiersFromDB)
                {
                    var curModel = new ClassificatorTreeModel();
                    curModel.Guid             = classifier["_id"].ToString();
                    curModel.Order            = (classifier["ord"] != DBNull.Value) ? Convert.ToInt32(classifier["ord"]) : (int?)null;
                    curModel.XmlId            = classifier["_xml_id"].ToString();
                    curModel.ClassifierTypeId = int.Parse(classifier["_classifier_type_id"].ToString());
                    curModel.TreeLevel        = i;

                    /*   if (Convert.ToBoolean(classifier["_has_assigned_caselaw"])) // change this later to real count for caselaw is needed
                     * {
                     *     curModel.DocumentCounts.Add("caselaw", new DocumentCountModel { Count = 1 });
                     * }
                     * else
                     * {
                     *     curModel.DocumentCounts.Add("caselaw", new DocumentCountModel { Count = 0 });
                     * }
                     *
                     *    if (Convert.ToBoolean(classifier["_has_assigned_legislation"])) // change this later to real count for legislation is needed
                     *    {
                     *        curModel.DocumentCounts.Add("legislation", new DocumentCountModel { Count = 1 });
                     *    }
                     *    else
                     *    {
                     *        curModel.DocumentCounts.Add("legislation", new DocumentCountModel { Count = 0 });
                     *    }
                     *
                     *    if (Convert.ToBoolean(classifier["_has_assigned_any_doc"]))
                     *    {
                     *        curModel.DocumentCounts.Add("any", new DocumentCountModel { Count = 1 });
                     *    }
                     *    else
                     *    {
                     *        curModel.DocumentCounts.Add("any", new DocumentCountModel { Count = 0 });
                     *    }*/

                    if (Convert.ToBoolean(classifier["_has_asigned_eurocases"]))
                    {
                        curModel.DocumentCounts.Add("eurocases", new DocumentCountModel {
                            Count = 1
                        });
                    }
                    else
                    {
                        curModel.DocumentCounts.Add("eurocases", new DocumentCountModel {
                            Count = 0
                        });
                    }

                    if (Convert.ToBoolean(classifier["_has_asigned_tfs"]))
                    {
                        curModel.DocumentCounts.Add("tfs", new DocumentCountModel {
                            Count = 1
                        });
                    }
                    else
                    {
                        curModel.DocumentCounts.Add("tfs", new DocumentCountModel {
                            Count = 0
                        });
                    }

                    var curLangIds = (int[])classifier["_langIds"];
                    var curTitles  = (string[])classifier["_langTitles"];
                    var curHints   = (string[])classifier["_langTooltips"];

                    if (curLangIds.Length == curTitles.Length)
                    {
                        for (int k = 0; k < curLangIds.Length; k++)
                        {
                            curModel.LanguageVariantsWithHints.Add(curLangIds[k].ToString(), new Pair()
                            {
                                Title = curTitles[k], Hint = curHints[k]
                            });
                        }
                    }

                    //  var curLangs = DB.GetClassifierLangs(classifier["_id"].ToString());

                    /* foreach (var lang in curLangs)
                     * {
                     *   curModel.LanguageVariants.Add(lang["lang_id"].ToString(), lang["title"].ToString());
                     * }*/

                    if (dic.ContainsKey(classifier["_parent_id"].ToString()))
                    {
                        curModel.Parent = dic[classifier["_parent_id"].ToString()];
                        dic[classifier["_parent_id"].ToString()].Children.Add(curModel);
                    }

                    dic.Add(curModel.Guid, curModel);
                }
            }

            var classifiers = new List <ClassificatorTreeModel>();

            var topLevelCount = DB.GetClassifiersTopLevelCount();

            for (int i = 0; i < topLevelCount; i++)
            {
                classifiers.Add(dic.Values.ElementAt(i));
            }

            var fictiveClassifier = new ClassificatorTreeModel();

            fictiveClassifier.Guid             = default(Guid).ToString();
            fictiveClassifier.TreeLevel        = 0;
            fictiveClassifier.ClassifierTypeId = 0;

            classifiers.Add(fictiveClassifier);

            return(classifiers);
        }