@@ -78,6 +78,20 @@ def update(self, table, id_record, values):
78
78
)
79
79
self .connection .commit ()
80
80
81
+ def update_where (self , table , where , values ):
82
+ cursor = self .connection .cursor ()
83
+ cursor .execute (
84
+ "UPDATE %s SET %s WHERE %s" % (
85
+ table ,
86
+ ", " .join ([
87
+ f"{ v [0 ]} = { self ._convert_value (v [1 ])} "
88
+ for v in values
89
+ ]),
90
+ where ,
91
+ )
92
+ )
93
+ self .connection .commit ()
94
+
81
95
def read (self , table , id_record ):
82
96
if isinstance (id_record , str ):
83
97
id_record = int (id_record .lower ().replace ("id-" , "" ))
@@ -269,18 +283,41 @@ class Articles(Vertical):
269
283
recomposes = reactive (0 , recompose = True )
270
284
feed = reactive (False , recompose = True )
271
285
filter_articles_type = reactive ("" , recompose = True )
286
+ filter_articles = reactive ("" , recompose = True )
272
287
273
288
def compose (self ) -> ComposeResult :
274
289
articles = []
275
290
if self .feed and self .feed .data :
276
291
data = self .feed .data
292
+ # Filter by Read/Unread
277
293
if self .filter_articles_type == "unread" :
278
294
read = " AND read = 0"
279
295
elif self .filter_articles_type == "read" :
280
296
read = " AND read = 1"
281
297
else :
282
298
read = ""
283
- articles = self .orm .search ("article" , ["id" , "date" , "title" ], where = f"feed_id = { data ["id" ]} { read } " )
299
+ # Filter by Title/Content
300
+ if self .filter_articles :
301
+ filters = self .filter_articles .split ("," )
302
+ filter_text = ""
303
+ for filter in filters :
304
+ filter = filter .strip ().replace ("\" " , "" )
305
+ if filter :
306
+ if filter .lower ().startswith ("title:" ):
307
+ filter = filter .replace ("title:" , "" )
308
+ filter_text = f"{ filter_text } AND title LIKE \" %{ filter } %\" "
309
+ elif filter .lower ().startswith ("content:" ):
310
+ filter = filter .replace ("content:" , "" )
311
+ filter_text = f"{ filter_text } AND content LIKE \" %{ filter } %\" "
312
+ else :
313
+ filter_text = f"{ filter_text } AND (title LIKE \" %{ filter } %\" OR content LIKE \" %{ filter } %\" )"
314
+ else :
315
+ filter_text = ""
316
+ articles = self .orm .search (
317
+ "article" ,
318
+ ["id" , "date" , "title" ],
319
+ where = f"feed_id = { data ["id" ]} { read } { filter_text } " ,
320
+ )
284
321
yield ListView (
285
322
* [
286
323
ListItem (
@@ -298,15 +335,24 @@ def compose(self) -> ComposeResult:
298
335
299
336
class ArticlesArea (Vertical ):
300
337
338
+ orm = ORM ()
339
+
301
340
def compose (self ) -> ComposeResult :
302
- yield Select (
303
- (
304
- ("Unread" , "unread" ),
305
- ("Read" , "read" ),
306
- ("All" , "all" ),
341
+ yield Horizontal (
342
+ Select (
343
+ (
344
+ ("Unread" , "unread" ),
345
+ ("Read" , "read" ),
346
+ ("All" , "all" ),
347
+ ),
348
+ value = "unread" ,
349
+ id = "filter_articles_type" ,
307
350
),
308
- value = "unread" ,
309
- id = "filter_articles_type" ,
351
+ Input (
352
+ placeholder = "Search " + Emoji .replace (":magnifying_glass_tilted_left:" ),
353
+ id = "search_articles" ,
354
+ ),
355
+ classes = "w100 hauto mb1" ,
310
356
)
311
357
yield Articles (
312
358
id = "articles"
@@ -317,6 +363,11 @@ def select_changed(self, event: Select.Changed) -> None:
317
363
if event .select .id == "filter_articles_type" :
318
364
self .query_one ("#articles" ).filter_articles_type = event .value
319
365
366
+ @on (Input .Changed )
367
+ def filter_articles (self , event : Input .Changed ) -> None :
368
+ if event .input .id == "search_articles" :
369
+ self .query_one ("#articles" ).filter_articles = event .value
370
+
320
371
321
372
class Reader (Vertical ):
322
373
@@ -357,6 +408,7 @@ class LugusApp(App):
357
408
("c" , "open_configuration" , "Configs" ),
358
409
("question_mark" , "article_data" , "Article Raw Data" ),
359
410
("r" , "article_read" , "Set Article as Read" ),
411
+ ("a" , "all_articles_read" , "Set all Feed Articles as Read" ),
360
412
("o" , "read_online" , "Read Online" ),
361
413
]
362
414
@@ -492,6 +544,19 @@ def action_article_read(self) -> None:
492
544
def action_open_configuration (self ) -> None :
493
545
self .status = "configuration"
494
546
547
+ def action_all_articles_read (self ) -> None :
548
+ feed = self .query_one ("#articles" ).feed
549
+ if not feed :
550
+ self .notify ("Select a feed" , severity = "warning" )
551
+ else :
552
+ self .orm .update_where (
553
+ "article" ,
554
+ f"feed_id = { feed .data ["id" ]} AND read = 0" ,
555
+ [("read" , 1 )],
556
+ )
557
+ self .query_one ("#sidebar" ).recomposes += 1
558
+ self .query_one ("#articles" ).recomposes += 1
559
+
495
560
def action_read_online (self ) -> None :
496
561
reader = self .query_one ("#reader" )
497
562
if not reader .id_article :
0 commit comments