mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-11-20 02:18:20 +01:00
fix
This commit is contained in:
parent
41d84a9c07
commit
31c371b2c1
@ -88,7 +88,8 @@ get.bytag = function(user, b64tag, limit, action, id)
|
||||
return data, sort
|
||||
end
|
||||
|
||||
get.analyse = function(user)
|
||||
get.analyse = function(user, n)
|
||||
if not n then n = 5 end
|
||||
local path = "/home/mrsang/aiws/blog-clustering"
|
||||
local gettext = loadfile(path.."/gettext.lua")()
|
||||
local cluster = loadfile(path.."/cluster.lua")()
|
||||
@ -111,7 +112,7 @@ get.analyse = function(user)
|
||||
db:delete({["="] = {["1"] = 1}})
|
||||
-- get similarity and put to the table
|
||||
for id,v in pairs(vectors) do
|
||||
local top = cluster.top_similarity(id,vectors,3)
|
||||
local top = cluster.top_similarity(id,vectors,n)
|
||||
for a,b in pairs(top) do
|
||||
local record = {pid = id, sid = a, score = b}
|
||||
db:insert(record)
|
||||
|
@ -534,3 +534,8 @@ afx-hbox.inputbox{
|
||||
margin-right: 10px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
div[data-id="status"]{
|
||||
padding-left: 10px;
|
||||
padding-top:5px;
|
||||
color:#724841;
|
||||
}
|
@ -87,10 +87,11 @@
|
||||
<ul>
|
||||
<li><i class = "fa fa-home"></i><a href="./">Home</a></li>
|
||||
<li ><i class = "fa fa-address-card"></i><a href="https://info.lxsang.me" >Porfolio</a></li>
|
||||
<li><i class = "fa fa-paper-plane"></i><a href="#" onclick="mailtoMe('rst')" >Contact</a></li>
|
||||
<li><i class = "fa fa-envelope"></i><a href="#" onclick="mailtoMe('rst')" >Contact</a></li>
|
||||
<?lua
|
||||
if not HEADER.mobile then
|
||||
?>
|
||||
<li> <i class = "fa fa-paper-plane"></i><a href="#" onclick="subscribe('rst')">Subscribe</a></li>
|
||||
<li > <i class = "fa fa-globe"></i><a href = "https://os.lxsang.me" target="_blank">AntOS</a></li>
|
||||
<?lua end ?>
|
||||
</ul>
|
||||
|
@ -1,6 +1,6 @@
|
||||
BUILDDIR = ../build/grs
|
||||
|
||||
copyfiles = katex font-awesome.css fonts images sendmail.lua main.js ubuntu-regular.css mainsite.css sendto.html hermit-light.css hljs
|
||||
copyfiles = katex font-awesome.css fonts images sendmail.lua subscribe.lua subscribe.html main.js ubuntu-regular.css mainsite.css sendto.html hermit-light.css hljs
|
||||
|
||||
main:
|
||||
- mkdir $(BUILDDIR)
|
||||
|
57
grs/main.js
57
grs/main.js
@ -3,6 +3,63 @@ String.prototype.__ = function()
|
||||
{
|
||||
return this
|
||||
}
|
||||
function subscribe(prefix)
|
||||
{
|
||||
if(scheme) return;
|
||||
// get scheme
|
||||
$.get(prefix+"/subscribe.html")
|
||||
.done(function(d) {
|
||||
scheme = $.parseHTML(d)
|
||||
var obs = riot.observable()
|
||||
$(scheme).css("visibility","hidden")
|
||||
$("#desktop" ).append(scheme)
|
||||
obs.on("exit", function(){
|
||||
$(scheme).remove()
|
||||
scheme = undefined
|
||||
})
|
||||
obs.on("rendered", function(d){
|
||||
$(".afx-window-title", scheme).html("Subscribe")
|
||||
$("[data-id='send']", scheme).click(function(){
|
||||
var status = $("[data-id='status']", scheme)
|
||||
status.html("");
|
||||
var els = $("[data-class='data']", scheme)
|
||||
var data = {}
|
||||
|
||||
for(var i = 0; i < els.length; i++)
|
||||
data[els[i].name] = $(els[i]).val()
|
||||
if(data.email == "" || data.subject == "" || data.content == "" || data.name == "")
|
||||
return status.html("Please enter all the fields");
|
||||
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
if(!re.test(String(data.email).toLowerCase()))
|
||||
return status.html("Email is not correct");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: prefix + "/subscribe.lua",
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
dataType: 'json',
|
||||
success: null
|
||||
}).done(function(r){
|
||||
if(r.error)
|
||||
alert(r.error)
|
||||
else
|
||||
{
|
||||
obs.trigger("exit")
|
||||
alert("You have been subscribed. Thanks")
|
||||
}
|
||||
}).fail(function(e, s){
|
||||
alert("Error: " + e)
|
||||
})
|
||||
})
|
||||
$(scheme).css("visibility","visible")
|
||||
})
|
||||
riot.mount(scheme, {observable:obs})
|
||||
})
|
||||
.fail(function() {
|
||||
alert( "Cannot get the form" );
|
||||
})
|
||||
}
|
||||
function mailtoMe(prefix)
|
||||
{
|
||||
if(scheme) return;
|
||||
|
24
grs/subscribe.html
Normal file
24
grs/subscribe.html
Normal file
@ -0,0 +1,24 @@
|
||||
<afx-app-window apptitle="Subscribe" minimizable="false" resizable = "false" width="350" height="170">
|
||||
<afx-vbox >
|
||||
<div data-height="5"></div>
|
||||
<afx-hbox data-height="50" class = "inputbox">
|
||||
<div styple="padding-left:5px;padding-right:5px;">Subscribe to receive an email when new post is published</div>
|
||||
</afx-hbox>
|
||||
<div data-height="5"></div>
|
||||
<afx-hbox data-height="20" class = "inputbox">
|
||||
<div data-width = "47" class = "label">Name:</div>
|
||||
<input data-class = "data" type = "text" name = "name" />
|
||||
</afx-hbox>
|
||||
<div data-height="5"></div>
|
||||
<afx-hbox data-height="20" class = "inputbox">
|
||||
<div data-width = "45" class = "label">Email:</div>
|
||||
<input data-class = "data" type = "text" name = "email" />
|
||||
</afx-hbox>
|
||||
<div data-height="5"></div>
|
||||
<afx-hbox data-height="30">
|
||||
<div data-id="status"></div>
|
||||
<button data-id = "send" data-width = "60" >Send</button>
|
||||
</afx-hbox>
|
||||
<div data-height="5"></div>
|
||||
</afx-vbox>
|
||||
</afx-app-window>
|
22
grs/subscribe.lua
Normal file
22
grs/subscribe.lua
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
if not REQUEST.query.json then
|
||||
fail("unknown request")
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.query.json))
|
||||
local sample = {name = "toto", email = "toto@mail.fr"}
|
||||
local db = require("db.model").get("mrsang","subscribers",sample)
|
||||
|
||||
if db then
|
||||
-- check if email is exist
|
||||
local data = db:find({exp = { ["="] = { email = rq.email } }})
|
||||
if data and #data > 0 then
|
||||
fail("You are already/previously subscribed")
|
||||
else
|
||||
-- save to database
|
||||
db:insert(rq)
|
||||
result("Ok")
|
||||
end
|
||||
db:close()
|
||||
else
|
||||
fail("Cannot subscribe at the moment, the service may be down")
|
||||
end
|
Loading…
Reference in New Issue
Block a user