コード例 #1
0
        public CustomFieldsViewModel(int?currentUserId, Character character, bool disableEdit = false, bool onlyPlayerVisible = false, bool wherePrintEnabled = false)
        {
            EditAllowed   = !disableEdit && character.Project.Active;
            CurrentUserId = currentUserId;
            if (onlyPlayerVisible)
            {
                HasMasterAccess            = false;
                HasPlayerAccessToCharacter = character.HasAnyAccess(currentUserId);
                HasPlayerClaimAccess       = character.ApprovedClaim?.HasAnyAccess(currentUserId) ?? false;
            }
            else
            {
                HasMasterAccess            = character.HasMasterAccess(currentUserId);
                HasPlayerAccessToCharacter = character.HasPlayerAccess(CurrentUserId);
                HasPlayerClaimAccess       = character.ApprovedClaim?.HasPlayerAccesToClaim(CurrentUserId) ?? false;
            }

            Target = character;
            var joinrpgMarkdownLinkRenderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            Fields =
                character.Project.GetFields()
                .Where(f => f.Field.FieldBoundTo == FieldBoundTo.Character && (!wherePrintEnabled || f.Field.IncludeInPrint))
                .ToList()
                .FillIfEnabled(character.ApprovedClaim, character)
                .Select(ch => new FieldValueViewModel(this, ch, joinrpgMarkdownLinkRenderer))
                .ToArray();
        }
コード例 #2
0
        /// <summary>
        ///  Called from
        /// - Character details
        /// - character list item
        /// - Edit character
        /// - print character
        /// </summary>
        /// <param name="currentUserId">ID of the currect user logged in</param>
        /// <param name="character">Character to print</param>
        /// <param name="disableEdit">disable editing (incl. cases where it's done to speeds up the app)</param>
        /// <param name="onlyPlayerVisible">
        /// Used for printing, when the user who prints has master access,
        /// whereas the print result should contain only user-visible fields.
        /// </param>
        /// <param name="wherePrintEnabled">when true - print only fields where IncludeInPrint = true</param>
        public CustomFieldsViewModel(
            int?currentUserId,
            Character character,
            bool disableEdit       = false,
            bool onlyPlayerVisible = false,
            bool wherePrintEnabled = false) : this()
        {
            EditAllowed = !disableEdit && character.Project.Active;
            if (onlyPlayerVisible)
            {
                AccessArguments = new AccessArguments(
                    masterAccess: false,
                    //TODO: this printing code might do smth wrong. Why Any access if we need palyer visible only?
                    playerAccessToCharacter: character.HasAnyAccess(currentUserId),
                    playerAccesToClaim: character.ApprovedClaim?.HasAccess(currentUserId, ExtraAccessReason.Player) ?? false);
            }
            else
            {
                AccessArguments = new AccessArguments(character, currentUserId);
            }

            Target = character;
            var joinrpgMarkdownLinkRenderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            Fields =
                character.Project.GetFieldsNotFilled()
                .Where(f => f.Field.FieldBoundTo == FieldBoundTo.Character)
                .Where(f => !wherePrintEnabled || f.Field.IncludeInPrint)
                .ToList()
                .FillIfEnabled(character.ApprovedClaim, character)
                .Select(ch => CreateFieldValueView(ch, joinrpgMarkdownLinkRenderer))
                .ToArray();
        }
コード例 #3
0
        private PlotDisplayViewModel([NotNull] IReadOnlyCollection <PlotElement> plots,
                                     int?currentUserId,
                                     [CanBeNull] Character character,
                                     bool publishedOnly,
                                     PlotElementType plotElementType,
                                     IUriService uriService)
        {
            if (plots == null)
            {
                throw new ArgumentNullException(nameof(plots));
            }


            var projectEntity   = ((IProjectEntity)character ?? plots.FirstOrDefault())?.Project;
            var hasMasterAccess = projectEntity?.HasMasterAccess(currentUserId) ?? false;

            var hasPlayerAccess = character?.HasPlayerAccess(currentUserId) ?? false;



            if (plots.Any() && projectEntity != null &&
                (hasMasterAccess || hasPlayerAccess || projectEntity.Details.PublishPlot))
            {
                if (!hasMasterAccess && !publishedOnly)
                {
                    throw new NoAccessToProjectException(projectEntity, currentUserId);
                }
                var linkRenderer = new JoinrpgMarkdownLinkRenderer(plots.First().Project);

                Func <PlotElement, PlotElementTexts> selector;
                if (!publishedOnly)
                {
                    selector = element => element.LastVersion();
                }
                else
                {
                    selector = element => element.PublishedVersion();
                }

                Elements = plots.Where(p => p.ElementType == plotElementType && p.IsActive == true)
                           .Select(selector)
                           .Where(p => p != null)
                           .Select(
                    p => new PlotElementViewModel(character,
                                                  currentUserId,
                                                  linkRenderer,
                                                  p,
                                                  uriService))
                           .MarkFirstAndLast();

                HasUnready = plots.Any(element => element.ElementType == plotElementType &&
                                       element.Published !=
                                       element.Texts.Max(text => text.Version));
            }
            else
            {
                Elements = Enumerable.Empty <PlotElementViewModel>();
            }
        }
コード例 #4
0
        /// <summary>
        /// Called from Claim and Claim list
        /// </summary>
        public CustomFieldsViewModel(int?currentUserId, Claim claim) : this()
        {
            AccessArguments = new AccessArguments(claim, currentUserId);

            Target      = claim.GetTarget();
            EditAllowed = claim.Project.Active;

            var renderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            Fields =
                claim.Project.GetFieldsNotFilled()
                .ToList()
                .FillIfEnabled(claim, claim.IsApproved ? claim.Character : null)
                .Select(ch => CreateFieldValueView(ch, renderer))
                .ToArray();
        }
コード例 #5
0
        public PlotElementListItemViewModel(PlotElement e, int?currentUserId)
        {
            var renderer = new JoinrpgMarkdownLinkRenderer(e.Project);

            PlotElementId     = e.PlotElementId;
            TargetsForDisplay = e.GetTargets().AsObjectLinks().ToList();
            Content           = e.Texts.Content.ToHtmlString(renderer);
            TodoField         = e.Texts.TodoField;
            ProjectId         = e.PlotFolder.ProjectId;
            PlotFolderId      = e.PlotFolderId;
            Status            = e.GetStatus();
            ElementType       = (PlotElementTypeView)e.ElementType;
            ShortContent      = e.Texts.Content.TakeWords(10).ToPlainText(renderer).WithDefaultStringValue("***");
            HasEditAccess     = e.PlotFolder.HasMasterAccess(currentUserId, acl => acl.CanManagePlots) && e.Project.Active;
            HasMasterAccess   = e.PlotFolder.HasMasterAccess(currentUserId);
        }
コード例 #6
0
        public CustomFieldsViewModel(int?currentUserId, IClaimSource target)
        {
            CurrentUserId   = currentUserId;
            HasMasterAccess = target.HasMasterAccess(currentUserId);
            EditAllowed     = target.Project.Active;

            Target = target;

            HasPlayerClaimAccess = true;
            var renderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            Fields =
                target.Project.GetFields()
                .Select(ch => new FieldValueViewModel(this, ch, renderer))
                .ToList();
        }
コード例 #7
0
        public PlotFolderListFullItemViewModel(PlotFolder folder, int?currentUserId, IUriService uriService) : base(folder, currentUserId)
        {
            Summary = folder.MasterSummary.ToHtmlString();

            if (folder.Elements.Any())
            {
                var linkRenderer = new JoinrpgMarkdownLinkRenderer(folder.Elements.First().Project);

                Elements = folder.Elements.Where(p => p.ElementType == PlotElementType.RegularPlot)
                           .Select(
                    p => new PlotElementViewModel(null, currentUserId, linkRenderer, p.LastVersion(), uriService))
                           .MarkFirstAndLast();
            }
            else
            {
                Elements = Enumerable.Empty <PlotElementViewModel>();
            }
        }
コード例 #8
0
        public CustomFieldsViewModel(int?currentUserId, Claim claim)
        {
            CurrentUserId   = currentUserId;
            HasMasterAccess = claim.HasMasterAccess(currentUserId);
            Target          = claim.GetTarget();
            EditAllowed     = claim.Project.Active;

            HasPlayerClaimAccess       = claim.HasPlayerAccesToClaim(CurrentUserId);
            HasPlayerAccessToCharacter = claim.Character != null && claim.Character.HasPlayerAccess(CurrentUserId);

            var renderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            Fields =
                claim.Project.GetFields()
                .ToList()
                .FillIfEnabled(claim, claim.IsApproved ? claim.Character : null)
                .Select(ch => new FieldValueViewModel(this, ch, renderer))
                .ToArray();
        }
コード例 #9
0
        /// <summary>
        /// Called from AddClaimViewModel
        /// </summary>
        public CustomFieldsViewModel(int?currentUserId, IClaimSource target)
        {
            CurrentUserId = currentUserId;

            AccessArguments = new AccessArguments(
                target.HasMasterAccess(currentUserId),
                playerAccessToCharacter: false,
                playerAccesToClaim: true);

            EditAllowed = target.Project.Active;

            Target = target;

            var renderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            Fields =
                target.Project.GetFieldsNotFilled()
                .Select(ch => new FieldValueViewModel(this, ch, renderer))
                .ToList();
        }
コード例 #10
0
        public PlotElementListItemViewModel(PlotElement e, int?currentUserId, IUriService uriService, int?currentVersion = null)
        {
            CurrentVersion = currentVersion ?? e.LastVersion().Version;

            var prevVersionText    = e.SpecificVersion(CurrentVersion - 1);
            var currentVersionText = e.SpecificVersion(CurrentVersion);
            var nextVersionText    = e.SpecificVersion(CurrentVersion + 1);

            if (currentVersionText == null)
            {
                throw new ArgumentOutOfRangeException(nameof(currentVersion));
            }

            var renderer = new JoinrpgMarkdownLinkRenderer(e.Project);

            PlotElementId     = e.PlotElementId;
            TargetsForDisplay = e.GetTargets().AsObjectLinks(uriService).ToList();
            Content           = currentVersionText.Content.ToHtmlString(renderer);
            TodoField         = currentVersionText.TodoField;
            ProjectId         = e.PlotFolder.ProjectId;
            PlotFolderId      = e.PlotFolderId;
            Status            = e.GetStatus();
            ElementType       = (PlotElementTypeView)e.ElementType;
            ShortContent      = currentVersionText.Content.TakeWords(10)
                                .ToPlainText(renderer).WithDefaultStringValue("***");
            HasEditAccess        = e.PlotFolder.HasMasterAccess(currentUserId, acl => acl.CanManagePlots) && e.Project.Active;
            HasMasterAccess      = e.PlotFolder.HasMasterAccess(currentUserId);
            ModifiedDateTime     = currentVersionText.ModifiedDateTime;
            Author               = currentVersionText.AuthorUser;
            PrevModifiedDateTime = prevVersionText?.ModifiedDateTime;
            NextModifiedDateTime = nextVersionText?.ModifiedDateTime;

            PlotFolderMasterTitle = e.PlotFolder.MasterTitle;

            PublishedVersion = e.Published;
        }
コード例 #11
0
        /// <summary>
        /// Called from AddClaimViewModel
        /// </summary>
        public CustomFieldsViewModel(int?currentUserId, IClaimSource target) : this()
        {
            AccessArguments = new AccessArguments(
                target.HasMasterAccess(currentUserId),
                playerAccessToCharacter: false,
                playerAccesToClaim: true);

            EditAllowed = target.Project.Active;

            Target = target;

            var renderer = new JoinrpgMarkdownLinkRenderer(Target.Project);

            var fieldsList = target.Project.GetFieldsNotFilled();

            if (target is Character character)
            {
                fieldsList.FillIfEnabled(claim: null, character: character);
            }
            Fields =
                fieldsList
                .Select(ch => CreateFieldValueView(ch, renderer))
                .ToList();
        }