コード例 #1
0
 public async Task <List <string> > GetFilesAsync()
 {
     if (_files == null)
     {
         _files = await ImageSelectionInfo.ReadFilesAsync(FolderGuid, SubFolder, FileType);
     }
     return(_files);
 }
コード例 #2
0
        private static async Task <List <string> > ReadFilePathsAsync(Guid folderGuid, string subFolder, string fileType)
        {
            List <string> files       = new List <string>();
            string        storagePath = ImageSelectionInfo.StoragePath(folderGuid, subFolder, fileType);

            if (await FileSystem.FileSystemProvider.DirectoryExistsAsync(storagePath))
            {
                files = await FileSystem.FileSystemProvider.GetFilesAsync(storagePath);
            }
            files = (from f in files where !f.EndsWith(".webp-gen") select f).ToList();
            return(files);
        }
コード例 #3
0
        public async Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            ImageSelectionInfo info = GetSiblingProperty <ImageSelectionInfo>($"{PropertyName}_Info");

            hb.Append($@"
<div id='{ControlId}' class='yt_imagerepository_imageselection'>
    {await HtmlHelper.ForEditComponentAsync(Container, PropertyName, model, "Hidden", HtmlAttributes: new { __NoTemplate = true }, Validation: true)}
    <div class='t_imgarea'>
        <div class='t_list'>
            <select class='t_native' name='List' size='10' style='height:{info.PreviewHeight}px'>");

            string modelPlain = model?.RemoveStartingAt(YetaWF.Core.Image.ImageSupport.ImageSeparator);

            foreach (var f in await info.GetFilesAsync())
            {
                string fPlain = f.RemoveStartingAt(YetaWF.Core.Image.ImageSupport.ImageSeparator);
                string sel    = fPlain == modelPlain ? " selected" : "";
                hb.Append($@"<option title='{HAE(fPlain)}' value='{HAE(f)}' {sel}>{HE(fPlain)}</option>");
            }

            hb.Append($@"
            </select>
        </div>
        <div class='t_preview'>
            <img src='{HAE(info.MakeImageUrl(model, info.PreviewWidth, info.PreviewHeight))}' alt='{__ResStr("preview", "Image Preview")}' />
        </div>
    </div>
    <div class='t_haveimage' {(string.IsNullOrWhiteSpace(model) ? "style='display:none'" : "")}>
        {await HtmlHelper.ForDisplayAsync(info, nameof(info.ClearImageButton))}
        {await HtmlHelper.ForDisplayAsync(info, nameof(info.RemoveImageButton))}
    </div>
    <div class='t_uploadarea'>
        {await HtmlHelper.ForEditAsync(info, nameof(info.FileUpload1))}
    </div>
</div>");

            Manager.ScriptManager.AddLast($@"new YetaWF_ImageRepository.ImageRepository('{ControlId}');");

            return(hb.ToString());
        }