< Summary

Class:SectionSceneAdminsSettingsView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/MenuSections/SectionSceneAdminsSettingsView.cs
Covered lines:62
Uncovered lines:9
Coverable lines:71
Total lines:170
Line coverage:87.3% (62 of 71)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSceneAdminsSettingsView()0%110100%
Awake()0%110100%
OnDestroy()0%110100%
Dispose()0%220100%
SetParent(...)0%2100%
SetActive(...)0%2100%
GetAdminsSearchPromptView()0%2100%
GetBlockedSearchPromptView()0%2100%
SetAdminsEmptyList(...)0%220100%
SetBannedUsersEmptyList(...)0%220100%
SetAdminsCount(...)0%110100%
SetBannedUsersCount(...)0%110100%
AddAdmin(...)0%110100%
AddBannedUser(...)0%110100%
RemoveAdmin(...)0%110100%
RemoveBannedUser(...)0%110100%
AddUser(...)0%660100%
RemoveUser(...)0%7.547077.78%
PoolView(...)0%110100%
GetView()0%220100%
ClearElementViewsDictionary(...)0%2.152066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/MenuSections/SectionSceneAdminsSettingsView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8internal class SectionSceneAdminsSettingsView : MonoBehaviour, IDisposable
 9{
 10    [SerializeField] internal UsersSearchPromptView adminsSearchPromptView;
 11    [SerializeField] internal UsersSearchPromptView blockedSearchPromptView;
 12    [SerializeField] internal Button addAdminButton;
 13    [SerializeField] internal Button addBlockedButton;
 14    [SerializeField] internal UserElementView adminElementView;
 15    [SerializeField] internal UserElementView blockedElementView;
 16    [SerializeField] internal Transform adminsContainer;
 17    [SerializeField] internal Transform blockedContainer;
 18    [SerializeField] internal GameObject adminsEmptyListContainer;
 19    [SerializeField] internal GameObject blockedEmptyListContainer;
 20    [SerializeField] internal TextMeshProUGUI labelAdmins;
 21    [SerializeField] internal TextMeshProUGUI labelBlocked;
 22
 23    public event Action OnSearchFriendButtonPressed;
 24    public event Action OnSearchUserButtonPressed;
 25
 926    internal readonly Dictionary<string, UserElementView> adminsElementViews = new Dictionary<string, UserElementView>()
 927    internal readonly Dictionary<string, UserElementView> bannedUsersElementViews = new Dictionary<string, UserElementVi
 928    private readonly Queue<UserElementView> userElementViewsPool = new Queue<UserElementView>();
 29
 30    private string adminsLabelFormat;
 31    private string blockedLabelFormat;
 32    private bool isDestroyed;
 33
 34    private void Awake()
 35    {
 836        addAdminButton.onClick.AddListener(() => OnSearchFriendButtonPressed?.Invoke());
 837        addBlockedButton.onClick.AddListener(() => OnSearchUserButtonPressed?.Invoke());
 838        PoolView(adminElementView);
 839        PoolView(blockedElementView);
 840        adminsLabelFormat = labelAdmins.text;
 841        blockedLabelFormat = labelBlocked.text;
 842    }
 43
 1644    private void OnDestroy() { isDestroyed = true; }
 45
 46    public void Dispose()
 47    {
 848        if (!isDestroyed)
 49        {
 850            Destroy(gameObject);
 51        }
 852    }
 53
 54    public void SetParent(Transform parent)
 55    {
 056        transform.SetParent(parent);
 057        transform.ResetLocalTRS();
 058    }
 59
 060    public void SetActive(bool active) { gameObject.SetActive(active); }
 61
 062    public UsersSearchPromptView GetAdminsSearchPromptView() { return adminsSearchPromptView; }
 63
 064    public UsersSearchPromptView GetBlockedSearchPromptView() { return blockedSearchPromptView; }
 65
 66    public void SetAdminsEmptyList(bool isEmpty)
 67    {
 668        adminsContainer.gameObject.SetActive(!isEmpty);
 669        adminsEmptyListContainer.SetActive(isEmpty);
 70
 671        if (isEmpty)
 72        {
 273            ClearElementViewsDictionary(adminsElementViews);
 74        }
 675    }
 76
 77    public void SetBannedUsersEmptyList(bool isEmpty)
 78    {
 679        blockedContainer.gameObject.SetActive(!isEmpty);
 680        blockedEmptyListContainer.SetActive(isEmpty);
 81
 682        if (isEmpty)
 83        {
 284            ClearElementViewsDictionary(bannedUsersElementViews);
 85        }
 686    }
 87
 1088    public void SetAdminsCount(int count) { labelAdmins.text = string.Format(adminsLabelFormat, count); }
 89
 1090    public void SetBannedUsersCount(int count) { labelBlocked.text = string.Format(blockedLabelFormat, count); }
 91
 792    public UserElementView AddAdmin(string userId) { return AddUser(userId, true); }
 93
 994    public UserElementView AddBannedUser(string userId) { return AddUser(userId, false); }
 95
 296    public bool RemoveAdmin(string userId) { return RemoveUser(userId, true); }
 97
 198    public bool RemoveBannedUser(string userId) { return RemoveUser(userId, false); }
 99
 100    UserElementView AddUser(string userId, bool addAsAdmin)
 101    {
 16102        var dictionary = addAsAdmin ? adminsElementViews : bannedUsersElementViews;
 16103        if (!dictionary.TryGetValue(userId, out UserElementView view))
 104        {
 12105            view = GetView();
 12106            view.SetUserName(userId);
 12107            view.SetUserId(userId);
 12108            view.SetAlwaysHighlighted(false);
 12109            view.SetIsAdded(true);
 12110            view.SetActive(true);
 12111            dictionary.Add(userId, view);
 112        }
 113
 16114        bool isBlocked = UserProfile.GetOwnUserProfile().blocked.Contains(userId);
 16115        view.SetBlocked(isBlocked);
 16116        view.SetParent(addAsAdmin ? adminsContainer : blockedContainer);
 16117        return view;
 118    }
 119
 120    bool RemoveUser(string userId, bool removeAsAdmin)
 121    {
 3122        var dictionary = removeAsAdmin ? adminsElementViews : bannedUsersElementViews;
 3123        if (!dictionary.TryGetValue(userId, out UserElementView view))
 124        {
 0125            return false;
 126        }
 127
 3128        Transform container = removeAsAdmin ? adminsContainer : blockedContainer;
 129
 3130        if (view.GetParent() != container)
 131        {
 0132            return false;
 133        }
 134
 3135        dictionary.Remove(userId);
 3136        PoolView(view);
 3137        return true;
 138    }
 139
 140    void PoolView(UserElementView view)
 141    {
 19142        view.SetActive(false);
 19143        userElementViewsPool.Enqueue(view);
 19144    }
 145
 146    UserElementView GetView()
 147    {
 148        UserElementView userView;
 149
 12150        if (userElementViewsPool.Count > 0)
 151        {
 8152            userView = userElementViewsPool.Dequeue();
 8153        }
 154        else
 155        {
 4156            userView = Instantiate(adminElementView, adminsContainer);
 157        }
 12158        userView.ClearThumbnail();
 12159        return userView;
 160    }
 161
 162    void ClearElementViewsDictionary(Dictionary<string, UserElementView> dictionary)
 163    {
 8164        foreach (UserElementView view in dictionary.Values)
 165        {
 0166            PoolView(view);
 167        }
 4168        dictionary.Clear();
 4169    }
 170}