Skip to content

Commit

Permalink
#5
Browse files Browse the repository at this point in the history
  • Loading branch information
JBJ05 committed May 26, 2023
1 parent c3c2b79 commit 077d15d
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using MultiPlug.Ext.FileImporter.Models.Components.FileImporter;
using MultiPlug.Base.Exchange;
using System.Linq;

namespace MultiPlug.Ext.FileImporter.Components.FileImporter
{
Expand All @@ -13,15 +14,15 @@ public FileImporterComponent(string theGuid)
Guid = theGuid;
Type = "Unknown";

RowEvent = new Event { Guid = System.Guid.NewGuid().ToString(), Id = "RowRead-" + theGuid, Description = "Row of a File", Subjects = new string[0]};
RowEvent = new Event { Guid = System.Guid.NewGuid().ToString(), Id = "RowRead-" + theGuid, Description = "Row of a File", Subjects = new string[0] };
}
internal void UpdateProperties(FileImporterProperties theNewProperties)
{
if(theNewProperties == null)
if (theNewProperties == null)
{
return;
}
if( theNewProperties.Guid != Guid)
if (theNewProperties.Guid != Guid)
{
return;
}
Expand All @@ -30,7 +31,7 @@ internal void UpdateProperties(FileImporterProperties theNewProperties)
Type = theNewProperties.Type;
}

if ( theNewProperties.RowEvent != null && Event.Merge(RowEvent, theNewProperties.RowEvent, true))
if (theNewProperties.RowEvent != null && Event.Merge(RowEvent, theNewProperties.RowEvent, true))
{
EventUpdated?.Invoke();
}
Expand Down Expand Up @@ -63,9 +64,39 @@ internal void Import(string thePath)
{
PayloadSubjects.Add(new PayloadSubject("Col" + (i + 1).ToString(), Columns[i]));
}

RowEvent.Invoke(new Payload(RowEvent.Id, PayloadSubjects.ToArray()));
}
}

internal void ReadHeaders(string thePath)
{
char Delimiter;

if (thePath.EndsWith(".tsv", StringComparison.OrdinalIgnoreCase))
{
Delimiter = '\t';
}
else if (thePath.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
Delimiter = ',';
}
else
{
return;
}

string Headings = System.IO.File.ReadLines(thePath).FirstOrDefault();

if (Headings != null)
{
string[] Columns = Headings.Split(Delimiter);

if (Columns.Length > 0)
{
RowEvent.Subjects = Columns;
EventUpdated.Invoke();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function NewHeading() {
return '<tr>\
<td class="span11"><input type="text" name="Headings" class="span3" placeholder="Heading Name" value=""></td>\
<td class="span11"><input form="form-headings" type="text" name="Headings" class="span3" placeholder="Heading Name" value=""></td>\
<td class="span1"><a class="btn btn-red btn-deleteHeading" href="#"><i class="icon-trash"></i></a></td>\
</tr>'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model MultiPlug.Base.Http.EdgeApp

<form action="" method="post" accept-charset="utf-8" enctype="application/x-www-form-urlencoded" autocomplete="off">
<form action="@Raw(Model.Context.Paths.Current)" id="form-headings" method="post" accept-charset="utf-8" enctype="application/x-www-form-urlencoded" autocomplete="off"></form>
<section class="row-fluid">
<div class="row-fluid">
<div class="box">
Expand All @@ -10,7 +10,7 @@
<p style="font-size:26px; line-height: 54px; text-align: center; margin: 0px;">File Importer</p>
</div>
<div class="span4" style="text-align: right;">
<button type="submit" value="submit" style="height:54px; width:65px" class="item btn btn-green"><i class="icon-save icon-large"></i><p>Save</p></button>
<button form="form-headings" type="submit" value="submit" style="height:54px; width:65px" class="item btn btn-green"><i class="icon-save icon-large"></i><p>Save</p></button>
</div>
</div>
</div>
Expand All @@ -21,8 +21,24 @@
<div class="row-fluid">
<div class="well">
<div class="row-fluid">
<input type="hidden" name="Guid" value="@Model.Extension.Model.Guid">
<input type="text" name="Description" class="span3" placeholder="File Type Description" value="@Raw(Model.Extension.Model.Description)">
<input form="form-headings" type="hidden" name="Guid" value="@Model.Extension.Model.Guid">
<label>File Type Description</label>
<input form="form-headings" type="text" name="Description" class="span3" placeholder="File Type Description" value="@Raw(Model.Extension.Model.Description)">
</div>
</div>
</div>
<h4>Use Example File to Populate Headings</h4>
<div class="row-fluid">
<div class="well">
<div class="row-fluid">
<div class=" span6">
<form action="@Raw(Model.Context.Paths.Current + "example/?id=" + Model.Extension.Model.Guid)" id="form-example-file" method="post" accept-charset="utf-8" enctype="multipart/form-data"></form>
<label>Example File</label>
<input form="form-example-file" type="file" name="file" accept=".tsv,.csv">
</div>
<div class=" span6">
<button form="form-example-file" type="submit" class="btn btn-green input-block-level">Upload</button>
</div>
</div>
</div>
</div>
Expand All @@ -36,7 +52,7 @@
{
<tr>
<td class="span11">
<input type="text" name="Headings" class="span3" placeholder="Heading Name" value="@Raw(Model.Extension.Model.Headings[i])">
<input form="form-headings" type="text" name="Headings" class="span3" placeholder="Heading Name" value="@Raw(Model.Extension.Model.Headings[i])">
</td>
<td class="span1">
<a class="btn btn-red btn-deleteHeading" href="#">
Expand All @@ -58,5 +74,5 @@
</div>
</section>
<script type="text/javascript" src="@Raw(Model.Context.Paths.Assets)js/file.js"></script>
</form>


Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using MultiPlug.Base.Attribute;
using MultiPlug.Base.Http;
using System.Linq;

namespace MultiPlug.Ext.FileImporter.Controllers.Settings.File
{
[Route("file/example")]
public class FileExampleController : SettingsApp
{
public FileExampleController()
{
}

public Response Post(string id, UploadFilePaths theFiles)
{
var Search = Core.Instance.Files.FirstOrDefault(File => File.Guid == id);

if (Search != null)
{
if (theFiles.Files.Length > 0)
{
try
{
Search.ReadHeaders(theFiles.Files[0].Path);
}
catch
{
}
}
}

return new Response
{
StatusCode = System.Net.HttpStatusCode.Moved,
Location = Context.Referrer
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MultiPlug.Ext.FileImporter.Controllers.Settings.File
{
internal class FileImporter
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
</div>
</td>
</tr>
}
<tr>
<td class="span10"></td>
<td class="span2"><button type="button" class="btn btn-green" id="btn-newfile"><i class="icon-plus"></i></button></td>
</tr>
}
<tr>
<td class="span10"></td>
<td class="span2"><button type="button" class="btn btn-green" id="btn-newfile"><i class="icon-plus"></i></button></td>
</tr>
</tbody>
</table>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<Compile Include="Controllers\Assets\JavaScript\JavaScriptController.cs" />
<Compile Include="Controllers\Settings\File\FileController.cs" />
<Compile Include="Controllers\Settings\File\FileDeleteController.cs" />
<Compile Include="Controllers\Settings\File\FileExampleController.cs" />
<Compile Include="Controllers\Settings\File\FileImporter.cs" />
<Compile Include="Controllers\Settings\Home\HomeController.cs" />
<Compile Include="Controllers\Settings\SettingsApp.cs" />
<Compile Include="Controllers\Shared\Templates.cs" />
Expand Down Expand Up @@ -99,8 +101,7 @@
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
<PostBuildEvent>xcopy "$(ProjectDir)bin\$(ConfigurationName)\MultiPlug.Ext.FileImporter.dll" "C:\Program Files (x86)\MultiPlug\Server\extensions\MultiPlug.Ext.FileImporter" /Y /I</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 077d15d

Please sign in to comment.