< Summary

Class:DCL.Builder.SectionSceneContributorsSettingsController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionSceneContributorsSettingsController.cs
Covered lines:42
Uncovered lines:26
Coverable lines:68
Total lines:130
Line coverage:61.7% (42 of 68)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSceneContributorsSettingsController(...)0%110100%
SectionSceneContributorsSettingsController()0%2100%
Dispose()0%110100%
SetViewContainer(...)0%2100%
OnShow()0%2100%
OnHide()0%2100%
OnSelectScene(...)0%2100%
UpdateContributors(...)0%6.496076.19%
AddContributor(...)0%2.012088.89%
OnAddUserPressed(...)0%12300%
OnRemoveUserPressed(...)0%3.013088.89%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using Object = UnityEngine.Object;
 6
 7namespace DCL.Builder
 8{
 9    internal class SectionSceneContributorsSettingsController : SectionBase, ISelectSceneListener, ISectionUpdateSceneCo
 10    {
 11        public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionSceneContributorsSettingsView";
 12
 13        public event Action<string, SceneContributorsUpdatePayload> OnRequestUpdateSceneContributors;
 14
 15        private readonly SectionSceneContributorsSettingsView view;
 16        private readonly FriendsSearchPromptController friendsSearchPromptController;
 417        private readonly UserProfileFetcher profileFetcher = new UserProfileFetcher();
 418        private readonly SceneContributorsUpdatePayload contributorsUpdatePayload = new SceneContributorsUpdatePayload()
 19
 420        private List<string> contributorsList = new List<string>();
 21        private string sceneId;
 22
 023        public SectionSceneContributorsSettingsController() : this(
 24            Object.Instantiate(Resources.Load<SectionSceneContributorsSettingsView>(VIEW_PREFAB_PATH)),
 25            FriendsController.i
 026        ) { }
 27
 428        public SectionSceneContributorsSettingsController(SectionSceneContributorsSettingsView view, IFriendsController 
 29        {
 430            this.view = view;
 431            friendsSearchPromptController = new FriendsSearchPromptController(view.GetSearchPromptView(), friendsControl
 32
 433            view.OnSearchUserButtonPressed += () => friendsSearchPromptController.Show();
 434            friendsSearchPromptController.OnAddUser += OnAddUserPressed;
 435            friendsSearchPromptController.OnRemoveUser += OnRemoveUserPressed;
 436        }
 37
 38        public override void Dispose()
 39        {
 440            view.Dispose();
 441            profileFetcher.Dispose();
 442            friendsSearchPromptController.Dispose();
 443        }
 44
 045        public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 46
 047        protected override void OnShow() { view.SetActive(true); }
 48
 049        protected override void OnHide() { view.SetActive(false); }
 50
 51        void ISelectSceneListener.OnSelectScene(ISceneCardView sceneCardView)
 52        {
 053            sceneId = sceneCardView.SceneData.id;
 054            UpdateContributors(sceneCardView.SceneData.contributors);
 055        }
 56
 57        internal void UpdateContributors(string[] contributors)
 58        {
 359            if (contributors == null || contributors.Length == 0)
 60            {
 061                if (contributorsList.Count > 0)
 062                    contributorsList.Clear();
 63
 064                view.SetEmptyList(true);
 065                view.SetContributorsCount(0);
 066                return;
 67            }
 68
 369            var newContributors = new List<string>(contributors);
 1870            for (int i = 0; i < newContributors.Count; i++)
 71            {
 672                AddContributor(newContributors[i]);
 673                contributorsList.Remove(newContributors[i]);
 74            }
 75
 876            for (int i = 0; i < contributorsList.Count; i++)
 77            {
 178                view.RemoveUser(contributorsList[i]);
 79            }
 80
 381            contributorsList = newContributors;
 82
 383            friendsSearchPromptController.SetUsersInRolList(contributorsList);
 384            view.SetEmptyList(false);
 385            view.SetContributorsCount(contributorsList.Count);
 386        }
 87
 88        void AddContributor(string userId)
 89        {
 690            if (string.IsNullOrEmpty(userId))
 091                return;
 92
 693            var userView = view.AddUser(userId);
 694            profileFetcher.FetchProfile(userId)
 095                          .Then(userProfile => userView.SetUserProfile(userProfile));
 96
 697            userView.OnAddPressed -= OnAddUserPressed;
 698            userView.OnRemovePressed -= OnRemoveUserPressed;
 699            userView.OnAddPressed += OnAddUserPressed;
 6100            userView.OnRemovePressed += OnRemoveUserPressed;
 6101        }
 102
 103        void OnAddUserPressed(string userId)
 104        {
 0105            if (contributorsList.Contains(userId))
 0106                return;
 107
 0108            contributorsList.Add(userId);
 0109            AddContributor(userId);
 0110            friendsSearchPromptController.SetUsersInRolList(contributorsList);
 0111            view.SetEmptyList(false);
 0112            view.SetContributorsCount(contributorsList.Count);
 0113            contributorsUpdatePayload.contributors = contributorsList.ToArray();
 0114            OnRequestUpdateSceneContributors?.Invoke(sceneId, contributorsUpdatePayload);
 0115        }
 116
 117        void OnRemoveUserPressed(string userId)
 118        {
 1119            if (!contributorsList.Remove(userId))
 0120                return;
 121
 1122            view.RemoveUser(userId);
 1123            friendsSearchPromptController.SetUsersInRolList(contributorsList);
 1124            view.SetEmptyList(contributorsList.Count == 0);
 1125            view.SetContributorsCount(contributorsList.Count);
 1126            contributorsUpdatePayload.contributors = contributorsList.ToArray();
 1127            OnRequestUpdateSceneContributors?.Invoke(sceneId, contributorsUpdatePayload);
 1128        }
 129    }
 130}