Skip to content

Commit 64c8af9

Browse files
committed
Nice
1 parent 9ed392f commit 64c8af9

File tree

8 files changed

+37
-23
lines changed

8 files changed

+37
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dev.sh
22
nimletter
33
db
4-
tests/sns_click
4+
tests/sns_click
5+
api

assets/js/table_load.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function tableContacts() {
6262
height:"70vh",
6363
layout:"fitColumns",
6464
ajaxURL:"/api/contacts/all",
65+
paginationSize:2000,
6566
progressiveLoad:"load",
6667
initialSort:[
6768
{column:"status", dir:"desc"},

nimletter.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.5.3"
3+
version = "0.5.5"
44
author = "ThomasTJdev"
55
description = "Newsletter"
66
license = "AGPL v3"

src/routes/routes_contacts.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ proc(request: Request) =
651651
if not c.loggedIn: resp Http401
652652

653653
let
654-
limit = (if @"limit" == "": 2000 else: @"limit".parseInt())
655-
offset = (if @"offset" == "": 0 else: @"offset".parseInt())
654+
limit = (if @"size" == "": 2000 else: @"size".parseInt())
655+
offset = (if @"page" == "": 0 elif @"page".parseInt() == 1: 0 else: (@"page".parseInt() - 1) * limit)
656656

657657
var
658658
contacts: seq[seq[string]]
@@ -725,8 +725,8 @@ proc(request: Request) =
725725
%* {
726726
"data": bodyJson,
727727
"count": contactsCount,
728-
"limit": limit,
729-
"offset": offset,
728+
"size": limit,
729+
"page": offset,
730730
"last_page": (if contactsCount == 0: 0 else: (contactsCount / limit).toInt()),
731731
}
732732
)

src/routes/routes_lists.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ proc(request: Request) =
3333

3434
let
3535
name = @"name"
36-
identifier = (if @"identifier" == "": name.toLowerAscii().replace(" ", "-").subStr(0, 20).strip(chars={'-', '_'}) else: @"identifier".replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}))
36+
identifier = (if @"identifier" == "": name.toLowerAscii().replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}) else: @"identifier".replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}))
3737
description = @"description"
3838
flowIDRaw = @"flowID"
3939
requireOptIn = @"requireOptIn" == "true"
@@ -159,7 +159,7 @@ proc(request: Request) =
159159
let
160160
listID = @"listID"
161161
name = @"name"
162-
identifier = (if @"identifier" == "": name.toLowerAscii().replace(" ", "-").subStr(0, 20).strip(chars={'-', '_'}) else: @"identifier".replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}))
162+
identifier = (if @"identifier" == "": name.toLowerAscii().replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}) else: @"identifier".replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}))
163163
description = @"description"
164164
requireOptIn = @"requireOptIn" == "true"
165165

src/routes/routes_mail.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ proc(request: Request) =
7171
"contentEditor",
7272
]),
7373
name,
74-
(name.toLowerAscii().replace(" ", "-").subStr(0, 20).strip(chars={'-', '_'})),
74+
(name.toLowerAscii().replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'})),
7575
"{" & formatTags(tags).join(",") & "}",
7676
category,
7777
contentHTML,
@@ -135,7 +135,7 @@ proc(request: Request) =
135135
"subject"
136136
]),
137137
mailData[1], # name
138-
mailData[1].toLowerAscii().replace(" ", "-").subStr(0, 20).strip(chars={'-', '_'}) & "-" & $rand(1000000), # identifier
138+
mailData[1].toLowerAscii().replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}) & "-" & $rand(1000000), # identifier
139139
mailData[2], # contentHTML
140140
mailData[3], # contentEditor
141141
mailData[4], # editorType
@@ -231,7 +231,7 @@ proc(request: Request) =
231231
let
232232
mailID = @"mailID"
233233
name = @"name".strip()
234-
identifier = (if @"identifier" == "": name.toLowerAscii().replace(" ", "-").subStr(0, 20).strip(chars={'-', '_'}) else: @"identifier".replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}))
234+
identifier = (if @"identifier" == "": name.toLowerAscii().replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}) else: @"identifier".replace(" ", "-").subStr(0, 100).strip(chars={'-', '_'}))
235235
tags = @"tags"
236236
category = @"category"
237237
sendOnce = (if @"sendOnce" == "true": true else: false)
@@ -354,8 +354,8 @@ proc(request: Request) =
354354
if not c.loggedIn: resp Http401
355355

356356
let
357-
limit = (if @"limit" == "": 2000 else: @"limit".parseInt())
358-
offset = (if @"offset" == "": 0 else: @"offset".parseInt())
357+
limit = (if @"size" == "": 2000 else: @"size".parseInt())
358+
offset = (if @"page" == "": 0 elif @"page".parseInt() == 1: 0 else: (@"page".parseInt() - 1) * limit)
359359

360360
var
361361
mails: seq[seq[string]]
@@ -413,8 +413,8 @@ proc(request: Request) =
413413
%* {
414414
"data": bodyJson,
415415
"count": mailsCount,
416-
"limit": limit,
417-
"offset": offset,
416+
"size": limit,
417+
"page": offset,
418418
"last_page": (if mailsCount == 0: 0 else: (mailsCount / limit).toInt())
419419
}
420420
)
@@ -428,8 +428,8 @@ proc(request: Request) =
428428
if not c.loggedIn: resp Http401
429429

430430
let
431-
limit = (if @"limit" == "": 2000 else: @"limit".parseInt())
432-
offset = (if @"offset" == "": 0 else: @"offset".parseInt())
431+
limit = (if @"size" == "": 2000 else: @"size".parseInt())
432+
offset = (if @"page" == "": 0 elif @"page".parseInt() == 1: 0 else: (@"page".parseInt() - 1) * limit)
433433

434434

435435
var
@@ -524,8 +524,8 @@ proc(request: Request) =
524524
%* {
525525
"data": bodyJson,
526526
"count": mailsCount,
527-
"limit": limit,
528-
"offset": offset,
527+
"size": limit,
528+
"page": offset,
529529
"last_page": (if mailsCount == 0: 0 else: (mailsCount / limit).toInt())
530530
}
531531
)

src/routes/routes_pending_emails.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ proc(request: Request) =
227227
if not c.loggedIn: resp Http401
228228

229229
let
230-
limit = (if @"limit" == "": "0" else: @"limit")
231-
offset = (if @"offset" == "": "0" else: @"offset")
230+
limit = (if @"size" == "": 2000 else: @"size".parseInt())
231+
offset = (if @"page" == "": 0 elif @"page".parseInt() == 1: 0 else: (@"page".parseInt() - 1) * limit)
232232

233233
var data: seq[seq[string]]
234234
pg.withConnection conn:
@@ -270,8 +270,8 @@ proc(request: Request) =
270270
resp Http200, (
271271
%* {
272272
"count": data.len(),
273-
"limit": limit,
274-
"offset": offset,
273+
"size": limit,
274+
"page": offset,
275275
"data": respJson
276276
}
277277
)

src/utils/contacts_utils.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,20 @@ proc addContactToPendinglist*(userID, listID: string): bool =
122122
return true
123123

124124

125+
proc isContactOnList*(userID, listID: string): bool =
126+
pg.withConnection conn:
127+
result = getValue(conn, sqlSelect(
128+
table = "subscriptions",
129+
select = ["id"],
130+
where = ["user_id = ?", "list_id = ?"]
131+
), userID, listID).len() > 0
132+
133+
125134
proc addContactToList*(userID, listID: string, flowStep = 1): bool =
126135
pg.withConnection conn:
136+
if isContactOnList(userID, listID):
137+
return true
138+
127139
if execAffectedRows(conn, sqlInsert(
128140
table = "subscriptions",
129141
data = [

0 commit comments

Comments
 (0)