< Summary

Class:DCL.Builder.SectionProjectController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionProjectController.cs
Covered lines:33
Uncovered lines:20
Coverable lines:53
Total lines:126
Line coverage:62.2% (33 of 53)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionProjectController(...)0%110100%
SectionProjectController()0%110100%
SetViewContainer(...)0%2100%
Dispose()0%110100%
OnShow()0%2100%
OnHide()0%2100%
CreateProjectRequest()0%6200%
OnSetProjects(...)0%220100%
OnProjectAdded(...)0%2100%
OnProjectRemoved(...)0%2100%
OnSearchResult(...)0%10.18068%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionProjectController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using Object = UnityEngine.Object;
 6
 7namespace DCL.Builder
 8{
 9    public interface ISectionProjectController
 10    {
 11        /// <summary>
 12        /// This event will be fired when the view request a new project creation
 13        /// </summary>
 14        event Action OnCreateProjectRequest;
 15    }
 16
 17    internal class SectionProjectController : SectionBase, IProjectsListener, ISectionHideContextMenuRequester,ISectionP
 18    {
 19        public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionProjectView";
 20
 21        public event Action OnRequestContextMenuHide;
 22        public event Action OnCreateProjectRequest;
 23
 024        public override ISectionSearchHandler searchHandler => sceneSearchHandler;
 25
 26        private readonly SectionProjectView view;
 27
 128        private readonly ISectionSearchHandler sceneSearchHandler = new SectionSearchHandler();
 129        internal Dictionary<string, IProjectCardView> projectsViews = new Dictionary<string, IProjectCardView>();
 30
 131        public SectionProjectController() : this(
 32            Object.Instantiate(Resources.Load<SectionProjectView>(VIEW_PREFAB_PATH))
 133        ) { }
 34
 135        public SectionProjectController(SectionProjectView view)
 36        {
 137            this.view = view;
 38
 139            view.OnScrollRectValueChanged += OnRequestContextMenuHide;
 140            view.OnCreateProjectRequest += CreateProjectRequest;
 141            sceneSearchHandler.OnResult += OnSearchResult;
 142        }
 43
 044        public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 45
 46        public override void Dispose()
 47        {
 148            view.OnScrollRectValueChanged -= OnRequestContextMenuHide;
 149            view.OnCreateProjectRequest -= CreateProjectRequest;
 150            sceneSearchHandler.OnResult -= OnSearchResult;
 151            view.Dispose();
 152        }
 53
 054        protected override void OnShow() { view.SetActive(true); }
 55
 056        protected override void OnHide() { view.SetActive(false); }
 57
 58        private void CreateProjectRequest()
 59        {
 060            OnCreateProjectRequest?.Invoke();
 061        }
 62
 63        void IProjectsListener.OnSetProjects(Dictionary<string, IProjectCardView> projectsViews)
 64        {
 165            this.projectsViews = new Dictionary<string, IProjectCardView>(projectsViews);
 266            sceneSearchHandler.SetSearchableList(projectsViews.Values.Select(project => project.searchInfo).ToList());
 167        }
 68
 69        void IProjectsListener.OnProjectAdded(IProjectCardView projectView)
 70        {
 071            projectsViews.Add(projectView.projectData.id, projectView);
 072            sceneSearchHandler.AddItem(projectView.searchInfo);
 073        }
 74
 75        void IProjectsListener.OnProjectRemoved(IProjectCardView projectView)
 76        {
 077            projectsViews.Remove(projectView.projectData.id);
 078            projectView.SetActive(false);
 079        }
 80
 81        internal void OnSearchResult(List<ISearchInfo> searchInfoScenes)
 82        {
 283            if (projectsViews == null)
 084                return;
 85
 286            using (var iterator = projectsViews.GetEnumerator())
 87            {
 488                while (iterator.MoveNext())
 89                {
 290                    iterator.Current.Value.SetParent(view.contentContainer.transform);
 291                    iterator.Current.Value.SetActive(false);
 92                }
 293            }
 94
 895            for (int i = 0; i < searchInfoScenes.Count; i++)
 96            {
 297                if (!projectsViews.TryGetValue(searchInfoScenes[i].id, out IProjectCardView cardView))
 98                    continue;
 99
 1100                cardView.SetActive(true);
 1101                cardView.SetSiblingIndex(i);
 102            }
 2103            view.ResetScrollRect();
 104
 2105            if (projectsViews.Count == 0)
 106            {
 0107                if (isLoading)
 108                {
 0109                    view.SetLoading();
 0110                }
 111                else
 112                {
 0113                    view.SetEmpty();
 114                }
 0115            }
 2116            else if (searchInfoScenes.Count == 0)
 117            {
 0118                view.SetNoSearchResult();
 0119            }
 120            else
 121            {
 2122                view.SetFilled();
 123            }
 2124        }
 125    }
 126}