I store alert messages in sessions and want to show them once after an action, for example ‘Topic is created successfully’. In DCG I’m trying to get a message and insert a div into html//1, but it doesn’t work. What am I doing wrong?
courses_body -->
{
functions:get_session_message(create_course_message, Message),
( \=(Message, '')
-> MessageDiv = [div(class('alert alert-success'), Message)]
)
},
html([
div(class(row),
div(class('col-sm-12'), [
\MessageDiv,
h1('Список курсов'),
a(href('/admin/courses/add'),
button([type("button"),class("btn btn-success")], 'Добавить курс')
)
])
)
]).
If functions:get_session_message/2
fails or Message
unifies with ''
then the whole production courses_body//0
fails. Then you should handle this case where you call it, or just add the else branch:
{
( functions:get_session_message(create_course_message, Message),
Message \= ''
-> MessageDiv = [div(class('alert alert-success'), Message)]
; MessageDiv=''
)
},
The outcome is a bit verbose when compared to imperative/functional languages… but overall, I’m not sure about the ‘temporal scope’ of your code. Maybe the whole problem is to lift the message in Javascript, or setup an AJAX roundtrip…
Well, it would be good to use JS and I was wondering is it possible to use a JS framework (ex. vue.js) with Prolog? I know how to launch JS frameworks via Apache or nginx, but how to connect it with web Prolog?
There are many variations about Javascript <-> SWI-Prolog interaction, a practical example and most simple example is WebChat, that shows websockets at work.
SWISH is a showcase for Pengines, but there the application is complex and hides the basic architecture…
I have never used VueJS - but have some experience with React (and React Native+Expo), Node+ExpressJS, Svelte.
I must say that I’m not a big fan of these, currently I prefer plain HTML5, eventually with jQueryUI.
Continuous improvements in JS (and PHP) have made the old LAMP architecture a good fit for my professional duties…
Maybe today will try to port to websockets the CLP(FD) visualization proposed by M.Triska.