diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..5e2afec --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "allow": [ + "Bash(powershell -Command \"Get-Content ''d:\\\\Development\\\\Tracking_Kits\\\\ImportService\\\\TrackingDataImport.vbs'' -Encoding Unicode | Out-String\")" + ] + } +} diff --git a/.gitignore b/.gitignore index 4e1086f..7bcd74a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.mdb *.ldb /volumes +/codex +*nul +gittoken.txt \ No newline at end of file diff --git a/App/Controllers/Jurisdiction/JurisdictionController.asp b/App/Controllers/Jurisdiction/JurisdictionController.asp index 2981170..9bdd895 100644 --- a/App/Controllers/Jurisdiction/JurisdictionController.asp +++ b/App/Controllers/Jurisdiction/JurisdictionController.asp @@ -169,22 +169,163 @@ Class JurisdictionController Public Sub ImportPost - Dim Upload:Set Upload = New FreeASPUpload - Upload.Save(server.mappath("/uploads")) - Chilkat_CSV.LoadFile(Upload.UploadedFiles("filename").path) - set Model = new PagedIndex_ViewModel_Class + Dim Upload: Set Upload = New FreeASPUpload + Dim uploadPath, uploadedFile, fileName, fileExt, fileSize + Dim maxFileSize, dotPos, recordCount + + maxFileSize = 10485760 '10 MB in bytes + uploadPath = Server.MapPath("/uploads") + + 'Parse upload data + Upload.Upload + + 'Validate file upload + If Upload.FileExists("filename") = False Then + Flash.AddError "No file selected for upload." + MVC.RedirectToAction "Import" + Exit Sub + End If + + Set uploadedFile = Upload.UploadedFiles("filename") + fileName = uploadedFile.FileName + fileSize = uploadedFile.Length + + 'Extract file extension + dotPos = InStrRev(fileName, ".") + If dotPos > 0 Then + fileExt = LCase(Mid(fileName, dotPos)) + Else + fileExt = "" + End If + + 'Validate file type + If fileExt <> ".csv" And fileExt <> ".txt" Then + Flash.AddError "Only .csv and .txt files are allowed." + MVC.RedirectToAction "Import" + Exit Sub + End If + + 'Validate file size + If fileSize > maxFileSize Then + Flash.AddError "File size exceeds 10 MB limit." + MVC.RedirectToAction "Import" + Exit Sub + End If + + 'Save the file to configured folder + Upload.Save uploadPath + + 'Remove the first line of the CSV (non-header info line) + StripFirstLine uploadedFile.Path + + 'Open CSV with Jet driver and iterate records + Dim conn, rs, connString, folderPath, csvFileName, fso + Set fso = Server.CreateObject("Scripting.FileSystemObject") + folderPath = fso.GetParentFolderName(uploadedFile.Path) + csvFileName = fso.GetFileName(uploadedFile.Path) + Set fso = Nothing + + Dim fmtType + If fileExt = ".txt" Then + fmtType = "TabDelimited" + Else + fmtType = "Delimited" + End If + connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & folderPath & ";Extended Properties=""text;HDR=YES;FMT=" & fmtType & """;" - Model.RecordCount = Chilkat_CSV.NumRows - Dim RowNumber + Set conn = Server.CreateObject("ADODB.Connection") On Error Resume Next - for RowNumber = 1 to Model.RecordCount + conn.Open connString + If Err.Number <> 0 Then + Flash.AddError "Unable to read CSV file." + MVC.RedirectToAction "Import" + Exit Sub + End If + On Error Goto 0 - Dim Record: Set Record = JurisdictionRepository.FindByJCode(Chilkat_CSV.GetCell(CLng(RowNumber),0)) + Dim sql + sql = "SELECT q.[County], q.[Jurisdiction], q.JCODE, " & _ + "IIf(InStr(1, UCase(q.NameRaw), ' CITY') > 0, " & _ + "'CITY OF ' & Trim(Replace(UCase(q.NameRaw), ' CITY', '')), " & _ + "q.NameRaw) AS [Name], " & _ + "q.[Mailing Address] AS Mailing_Address, " & _ + "q.[City & Township] & ' ' & q.[ZIP + 4] AS CSZ, " & _ + "'' AS IMB, " & _ + "'007' & q.[Mailer ID Option 1] & '000000' & Replace(q.[ZIP + 4], '-', '') AS IMB_Digits " & _ + "FROM (" & _ + "SELECT [County], [Jurisdiction], [Mailing Address], [City & Township], [ZIP + 4], [Mailer ID Option 1], " & _ + "IIf(InStr(1,[Jurisdiction],'(') > 0 And InStr(1,[Jurisdiction],')') > InStr(1,[Jurisdiction],'('), " & _ + "Trim(Mid([Jurisdiction], InStr(1,[Jurisdiction],'(') + 1, InStr(1,[Jurisdiction],')') - InStr(1,[Jurisdiction],'(') - 1)), " & _ + "Null) AS JCODE, " & _ + "IIf(InStr(1,[Jurisdiction],'(') > 0, " & _ + "Trim(Left([Jurisdiction], InStr(1,[Jurisdiction],'(') - 1)), " & _ + "Trim([Jurisdiction])) AS NameRaw " & _ + "FROM [" & csvFileName & "]) AS q" + + Set rs = conn.Execute(sql) + + recordCount = 0 + Do While Not rs.EOF + Dim jurisdiction : Set jurisdiction = New JurisdictionModel_Class + jurisdiction.JCode = Trim(rs.Fields("JCODE").Value & "") + jurisdiction.Name = Trim(rs.Fields("Name").Value & "") + jurisdiction.Mailing_Address = Trim(rs.Fields("Mailing_Address").Value & "") + jurisdiction.CSZ = Trim(rs.Fields("CSZ").Value & "") + jurisdiction.IMB_Digits = Trim(rs.Fields("IMB_Digits").Value & "") + jurisdiction.IMB = GetIMBCodec.EncodeDigits(jurisdiction.IMB_Digits) + + 'JurisdictionRepository.AddNew jurisdiction + + recordCount = recordCount + 1 + rs.MoveNext + Loop + + rs.Close + conn.Close + Set rs = Nothing + Set conn = Nothing + + 'Set success message with record count + Flash.Success = "File '" & fileName & "' uploaded successfully. Records imported: " & recordCount + MVC.RedirectToAction "Import" - Next - On Error Goto 0 - %> <% + End Sub + + Private Sub StripFirstLine(filePath) + Dim fso, ts, remainingText + + Set fso = Server.CreateObject("Scripting.FileSystemObject") + If Not fso.FileExists(filePath) Then + Set fso = Nothing + Exit Sub + End If + + Set ts = fso.OpenTextFile(filePath, 1) ' 1 = ForReading + If ts.AtEndOfStream Then + ts.Close + Set ts = Nothing + Set fso = Nothing + Exit Sub + End If + + 'Skip the first line + ts.ReadLine + + 'Read the rest of the file + If Not ts.AtEndOfStream Then + remainingText = ts.ReadAll + Else + remainingText = "" + End If + ts.Close + + 'Rewrite the file without the first line + Set ts = fso.OpenTextFile(filePath, 2) ' 2 = ForWriting + ts.Write remainingText + ts.Close + Set ts = Nothing + Set fso = Nothing End Sub End Class MVC.Dispatch diff --git a/App/Views/Jurisdiction/import.asp b/App/Views/Jurisdiction/import.asp index 80f52cc..393d181 100644 --- a/App/Views/Jurisdiction/import.asp +++ b/App/Views/Jurisdiction/import.asp @@ -1,23 +1,25 @@ -

Create Jurisdiction

+

Import Jurisdiction

+ +<% Flash().ShowErrorsIfPresent %> +<% Flash().ShowSuccessIfPresent %> <%= HTML.FormTag("Jurisdiction", "ImportPost", empty, Array("enctype","multipart/form-data")) %> <%= HTML.Hidden("nonce", HTMLSecurity.GetAntiCSRFToken("JurisdictionImportForm")) %>
-

This will delete all records and import the new records from the file

-<% if Model.RecordCount <> 0 Then %> -

Records in the CSV: <%= Model.RecordCount %>

-<% End If %> +

Upload a CSV (.csv) or tab-delimited (.txt) file to import jurisdiction data

+
- - + +

<%= HTML.Button("submit", " Upload", "btn-primary") %> + Accepted formats: .csv, .txt | Max size: 10 MB
diff --git a/Data/Update_Addresses.ps1 b/Data/Update_Addresses.ps1 index 955e17d..bde0778 100644 --- a/Data/Update_Addresses.ps1 +++ b/Data/Update_Addresses.ps1 @@ -1,5 +1,5 @@ # Define file paths -$excelFilePath = "C:\Users\danielc\Desktop\Changed Addrs17.xlsx" +$excelFilePath = "C:\Users\danielc\Desktop\Changed Addrs18.xlsx" $accessDbPath = "\\kci-app01\c$\inetpub\Data\webdata - Copy.mdb" $tableName = "Jurisdiction" diff --git a/Dockerfile b/Dockerfile index 43ae348..3b7b5fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,14 @@ FROM node:20-bookworm -# Useful dev tools (git is handy because Codex often interacts with repos) -RUN apt-get update && apt-get install -y --no-install-recommends \ +# Install GitHub Copilot CLI +RUN npm install -g @github/copilot + +# Install useful dev tools +RUN apt-get update && apt-get install -y \ git \ - openssh-client \ - ca-certificates \ - ripgrep \ + curl \ && rm -rf /var/lib/apt/lists/* -# Install Codex CLI -RUN npm i -g @openai/codex@latest - WORKDIR /workspace + CMD ["bash"] diff --git a/ImportService/TrackingDataImport.vbs b/ImportService/TrackingDataImport.vbs index 9737ae5..628498a 100644 Binary files a/ImportService/TrackingDataImport.vbs and b/ImportService/TrackingDataImport.vbs differ diff --git a/MVC/lib.Flash.asp b/MVC/lib.Flash.asp index b154858..ff0fd38 100644 --- a/MVC/lib.Flash.asp +++ b/MVC/lib.Flash.asp @@ -55,18 +55,24 @@ Class Flash_Class Public Sub ShowErrors if HasErrors then %> -
- -

Error!

-