< 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:34
Uncovered lines:38
Coverable lines:72
Total lines:168
Line coverage:47.2% (34 of 72)
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%42600%
OnHide()0%2100%
CreateProjectRequest()0%6200%
OnSetProjects(...)0%220100%
OnProjectAdded(...)0%2100%
OnProjectRemoved(...)0%2100%
OnFetchingStateChange(...)0%6200%
OnSearchResult(...)0%22.212058.62%

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
 124        public override SearchBarConfig searchBarConfig { get; protected set; } = new SearchBarConfig()
 25        {
 26            showFilterContributor = false,
 27            showFilterOperator = false,
 28            showFilterOwner = false,
 29            showResultLabel = true
 30        };
 31
 032        public override ISectionSearchHandler searchHandler => sceneSearchHandler;
 33
 34        private readonly SectionProjectView view;
 35
 136        private readonly ISectionSearchHandler sceneSearchHandler = new SectionSearchHandler();
 137        internal Dictionary<string, IProjectCardView> projectsViews = new Dictionary<string, IProjectCardView>();
 38
 139        public SectionProjectController() : this(
 40            Object.Instantiate(Resources.Load<SectionProjectView>(VIEW_PREFAB_PATH))
 141        ) { }
 42
 143        public SectionProjectController(SectionProjectView view)
 44        {
 145            this.view = view;
 46
 147            view.OnScrollRectValueChanged += OnRequestContextMenuHide;
 148            view.OnCreateProjectRequest += CreateProjectRequest;
 149            sceneSearchHandler.OnResult += OnSearchResult;
 150        }
 51
 052        public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 53
 54        public override void Dispose()
 55        {
 156            view.OnScrollRectValueChanged -= OnRequestContextMenuHide;
 157            view.OnCreateProjectRequest -= CreateProjectRequest;
 158            sceneSearchHandler.OnResult -= OnSearchResult;
 159            view.Dispose();
 160        }
 61
 62        protected override void OnShow()
 63        {
 064            view.SetActive(true);
 065            if (projectsViews.Count == 0)
 66            {
 067                if (isLoading)
 68                {
 069                    view.SetLoading();
 070                    OnNotEmptyContent?.Invoke();
 071                }
 72                else
 73                {
 074                    view.SetEmpty();
 075                    OnEmptyContent?.Invoke();
 76                }
 077            }
 78            else
 79            {
 080                OnNotEmptyContent?.Invoke();
 81            }
 082        }
 83
 084        protected override void OnHide() { view.SetActive(false); }
 85
 86        private void CreateProjectRequest()
 87        {
 088            OnCreateProjectRequest?.Invoke();
 089        }
 90
 91        void IProjectsListener.OnSetProjects(Dictionary<string, IProjectCardView> projectsViews)
 92        {
 193            this.projectsViews = new Dictionary<string, IProjectCardView>(projectsViews);
 294            sceneSearchHandler.SetSearchableList(projectsViews.Values.Select(project => project.searchInfo).ToList());
 195        }
 96
 97        void IProjectsListener.OnProjectAdded(IProjectCardView projectView)
 98        {
 099            projectsViews.Add(projectView.projectData.id, projectView);
 0100            sceneSearchHandler.AddItem(projectView.searchInfo);
 0101        }
 102
 103        void IProjectsListener.OnProjectRemoved(IProjectCardView projectView)
 104        {
 0105            projectsViews.Remove(projectView.projectData.id);
 0106            projectView.SetActive(false);
 0107        }
 108
 109        protected override void OnFetchingStateChange(bool isLoading)
 110        {
 0111            base.OnFetchingStateChange(isLoading);
 0112            if (isLoading)
 113            {
 0114                view.SetLoading();
 115            }
 0116        }
 117
 118        internal void OnSearchResult(List<ISearchInfo> searchInfoScenes)
 119        {
 2120            if (projectsViews == null)
 0121                return;
 122
 2123            using (var iterator = projectsViews.GetEnumerator())
 124            {
 4125                while (iterator.MoveNext())
 126                {
 2127                    iterator.Current.Value.SetParent(view.contentContainer.transform);
 2128                    iterator.Current.Value.SetActive(false);
 129                }
 2130            }
 131
 8132            for (int i = 0; i < searchInfoScenes.Count; i++)
 133            {
 2134                if (!projectsViews.TryGetValue(searchInfoScenes[i].id, out IProjectCardView cardView))
 135                    continue;
 136
 1137                cardView.SetActive(true);
 1138                cardView.SetSiblingIndex(i);
 139            }
 2140            view.ResetScrollRect();
 141
 2142            if (projectsViews.Count == 0)
 143            {
 0144                if (isLoading)
 145                {
 0146                    view.SetLoading();
 0147                    OnNotEmptyContent?.Invoke();
 0148                }
 149                else
 150                {
 0151                    view.SetEmpty();
 0152                    OnEmptyContent?.Invoke();
 153                }
 0154            }
 2155            else if (searchInfoScenes.Count == 0)
 156            {
 0157                view.SetNoSearchResult();
 158
 0159                OnNotEmptyContent?.Invoke();
 0160            }
 161            else
 162            {
 2163                view.SetFilled();
 2164                OnNotEmptyContent?.Invoke();
 165            }
 0166        }
 167    }
 168}