< Summary

Class:NewProjectFlowController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/NewProject/NewProjectFlowController.cs
Covered lines:29
Uncovered lines:7
Coverable lines:36
Total lines:109
Line coverage:80.5% (29 of 36)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NewProjectFlowController()0%2100%
NewProjectFlowController(...)0%110100%
Initilizate(...)0%110100%
Hide()0%2100%
Dispose()0%110100%
IsActive()0%2100%
NewProject()0%110100%
SetTitleAndDescription(...)0%110100%
SetRowsAndColumns(...)0%110100%
NewProjectCreated()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/NewProject/NewProjectFlowController.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL.Builder;
 5using UnityEngine;
 6using Object = UnityEngine.Object;
 7
 8public interface INewProjectFlowController
 9{
 10    /// <summary>
 11    /// When a new project is created
 12    /// </summary>
 13    event Action<ProjectData> OnNewProjectCrated;
 14
 15    /// <summary>
 16    /// This will create a new project data and show the view to create it
 17    /// </summary>
 18    void NewProject();
 19
 20    /// <summary>
 21    /// Hide the view
 22    /// </summary>
 23    void Hide();
 24
 25    void Dispose();
 26
 27    /// <summary>
 28    /// This will return true if the new project windows is active
 29    /// </summary>
 30    /// <returns></returns>
 31    bool IsActive();
 32}
 33
 34public class NewProjectFlowController : INewProjectFlowController
 35{
 36    public const string VIEW_PATH = "NewProject/NewProjectFlowView";
 37
 38    public event Action<ProjectData> OnNewProjectCrated;
 39
 40    internal ProjectData projectData;
 41
 42    internal INewProjectFlowView view;
 43
 044    public NewProjectFlowController()
 45    {
 046        var prefab = Resources.Load<NewProjectFlowView>(VIEW_PATH);
 047        var instantiateView = Object.Instantiate(prefab);
 048        Initilizate(instantiateView);
 049    }
 50
 451    public NewProjectFlowController(INewProjectFlowView view)
 52    {
 453        Initilizate(view);
 454    }
 55
 56    private void Initilizate(INewProjectFlowView view)
 57    {
 458        this.view = view;
 459        view.OnTittleAndDescriptionSet += SetTitleAndDescription;
 460        view.OnSizeSet += SetRowsAndColumns;
 461    }
 62
 063    public void Hide() { view.Hide(); }
 64
 65    public void Dispose()
 66    {
 467        view.OnTittleAndDescriptionSet -= SetTitleAndDescription;
 468        view.OnSizeSet -= SetRowsAndColumns;
 469        view.Dispose();
 470    }
 71
 72    public bool IsActive()
 73    {
 074        return view.IsActive();
 75    }
 76
 77    public void NewProject()
 78    {
 479        projectData = new ProjectData();
 480        projectData.id = Guid.NewGuid().ToString();
 481        projectData.eth_address = UserProfile.GetOwnUserProfile().ethAddress;
 82
 483        view.ShowNewProjectTitleAndDescrition();
 484    }
 85
 86    public void SetTitleAndDescription(string title, string description)
 87    {
 188        projectData.title = title;
 189        projectData.description = description;
 190    }
 91
 92    public void SetRowsAndColumns(int rows, int columns)
 93    {
 194        projectData.rows = rows;
 195        projectData.cols = columns;
 96
 197        NewProjectCreated();
 198    }
 99
 100    internal void NewProjectCreated()
 101    {
 2102        projectData.created_at = DateTime.UtcNow;
 2103        projectData.updated_at = DateTime.UtcNow;
 104
 2105        view.Reset();
 2106        OnNewProjectCrated?.Invoke(projectData);
 2107        view.Hide();
 2108    }
 109}