Hello friends,
I start a project for easy management of links.
As project name I choose SEAMAP.
I start with a simple dbf table.
There should be a user mode and an admin mode.
I post my progress here regularly. I think such a program could be of interest for many of us.
You can see SEAMAP in Action here: http://modharbour.online
Best regards
Otto
mod harbour "SEAMAP"
mod harbour "SEAMAP"
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: mod harbour "SEAMAP"
Dear Antonio,
now I have ready the dbrowse and would like to have the buttons "new", "edit", "delete" and "mark" working.
script inside code is replaced by s cript as otherwise I can't post the code here.
Best regards,
Otto
now I have ready the dbrowse and would like to have the buttons "new", "edit", "delete" and "mark" working.
script inside code is replaced by s cript as otherwise I can't post the code here.
Best regards,
Otto
Code: Select all
function Main()
local alinks := {}
if ! File( hb_GetEnv( "PRGPATH" ) + "/links.dbf" )
DbCreate( hb_GetEnv( "PRGPATH" ) + "/links.dbf",;
{ { "LINKDEST", "C", 200, 0 },;
{ "LINKNAME", "C", 200, 0 },;
{ "LONGTEXT", "M", 10, 0 } } )
endif
USE ( hb_GetEnv( "PRGPATH" ) + "/links" ) SHARED NEW
do while .not. eof()
aadd( alinks, { field->linkdest, field->linkname, field->longtext } )
skip
enddo
USE
TEMPLATE PARAMS alinks
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
<s cript src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></s cript>
<s cript src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></s cript>
<style>
.table-striped>tbody>tr:nth-of-type(odd) {background-color: #ecf3f7;}
.table-striped>tbody>tr:nth-of-type(even) {background-color: #e1ebf2;}
.table-striped>tbody>tr:hover>td {background-color: #f6f4d0;}
</style>
</head>
<body>
<div class="container">
<img src="assets/seamap.jpg" />
<div class="row">
<table class="table col-12" style="font-size:20px;">
<thead class="thead-dark ">
<tr>
<th scope="col">#</th>
<th scope="col">Project Name</th>
<!-- adminmode -->
<th>
<div class="btn-group">
<a class="btn btn-default" style="background-color:#0ed145;" onclick="neu()" ><span>New</span></a>
</div>
</th>
</tr>
</thead>
<tbody>
<?prg local I := 0, cRow := "" //mod harbour code inside HTML TAG starts with <?prg
for I := 1 to len( alinks )
cRow += '<tr>'
cRow += '<th scope="row">' + ALLTRIM( str(I) ) + '</th>'
cRow += "<td><a target='_blank' href=" + alinks[I,1] + ">" + alinks[I,2] + "</a>"
cRow += '<br>'
cRow += alinks[I,3]
cRow += "</td>"
//adminmode
cRow += "<td>"
cRow += '<button type="button" class="btn btn-xs btn-default">'
cRow += ' <span class="glyphicon glyphicon-pencil"></span>'
cRow += "</button>"
cRow += '<button type="button" data-bind="click: $parent.remove" class="remove-news btn btn-xs btn-default" data-toggle="tooltip" data-placement="top" data-original-title="Delete">'
cRow += ' <span class="glyphicon glyphicon-trash"></span>'
cRow += "</button>"
cRow += '<button type="button" class="enabledisable-news btn btn-xs btn-default">'
cRow += ' <span class="glyphicon glyphicon-ok"></span>'
cRow += "</button>"
cRow += "</td>"
next
return cRow ?>
</tbody>
</table>
</div>
</div>
<s cript>
$(document).ready( function () {
$('#new').on( 'click', function( e ){
$.alert( "New" );
});
});
function neu() {
alert('neuer Link');
}
</s cript>
</body>
</html>
ENDTEXT
return nil
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: mod harbour "SEAMAP"
Antonio Linares 19:52 Uhr
When we build a simple utility, in fact we use a small MVC model
So first of all, we implement a very simple "router" (seria correcto decirle "router" ó "controller" ?)
seamap.prg
When we build a simple utility, in fact we use a small MVC model
So first of all, we implement a very simple "router" (seria correcto decirle "router" ó "controller" ?)
seamap.prg
Code: Select all
function Main()
local cMethod := AP_Method()
local aArgs := hb_aTokens( AP_Args(), ":" )
do case
case cMethod == "GET"
? "We process a GET"
do case
case aArgs[ 1 ] == "add"
? "add is required" case aArgs[ 1 ] == "edit"
? "edit is required" case aArgs[ 1 ] == "next"
? "browse next is required" case aArgs[ 1 ] == "prev"
? "browse prev is required" case aArgs[ 1 ] == "del"
? "del is required"
endcase case cMethod == "POST"
? "We process a POST"
endcasereturn nil
1. We distinct between "GET" and "POST"
2. We identify the action to perform
so just using AP_Method() and AP_Args() we start it
I missed "save". So I guess this is the simplest "controller" that we can have for a DBF
function Main() local cMethod := AP_Method()
local aArgs := hb_aTokens( AP_Args(), ":" ) do case
case cMethod == "GET"
? "We process a GET"
do case
case aArgs[ 1 ] == "add"
? "add is required" case aArgs[ 1 ] == "edit"
? "edit is required" case aArgs[ 1 ] == "next"
? "browse next is required" case aArgs[ 1 ] == "prev"
? "browse prev is required" case aArgs[ 1 ] == "del"
? "del is required"
endcase case cMethod == "POST"
? "We process a POST"
do case
case aArgs[ 1 ] == "save"
? "save is required"
endcase
endcasereturn nil
In fact, this is a very small and reduced MVC model ( just the "C"ontroller, for now)
The "M"odel is in charge of the data
Now we check that the DBF exists, if not we create it, and then we "USE" it
function Main() local cMethod := AP_Method()
local aArgs := hb_aTokens( AP_Args(), ":" ) CheckTables() do case
case cMethod == "GET"
? "We process a GET"
do case
case aArgs[ 1 ] == "add"
? "add is required" case aArgs[ 1 ] == "edit"
? "edit is required" case aArgs[ 1 ] == "next"
? "browse next is required" case aArgs[ 1 ] == "prev"
? "browse prev is required" case aArgs[ 1 ] == "del"
? "del is required"
endcase case cMethod == "POST"
? "We process a POST"
do case
case aArgs[ 1 ] == "save"
? "save is required"
endcase
endcasereturn nilfunction CheckTables() if ! File( hb_GetEnv( "PRGPATH" ) + "/links.dbf" )
DbCreate( hb_GetEnv( "PRGPATH" ) + "/links.dbf",;
{ { "LINKDEST", "C", 200, 0 },;
{ "LINKNAME", "C", 200, 0 },;
{ "LONGTEXT", "M", 10, 0 } } )
endif USE ( hb_GetEnv( "PRGPATH" ) + "/links" ) SHARED NEWreturn nil
In fact, in the MVC design, the "C"ontroller is in charge to "Talk" to the "M"odel to tell it what to do
If we put a little of object oriented programming for a better structured code we get:
// {% hb_SetEnv( "HB_INCLUDE", "/Users/anto/harbour/include" ) %}#include "hbclass.ch"function Main() CheckTables()
Controller()return nilfunction Controller() local cMethod := AP_Method()
local aArgs := hb_aTokens( AP_Args(), ":" )
local oModel := Model():New() do case
case cMethod == "GET"
? "We process a GET"
do case
case aArgs[ 1 ] == "add"
? "add is required"
oModel:Add() case aArgs[ 1 ] == "edit"
? "edit is required"
oModel:Edit() case aArgs[ 1 ] == "next"
? "browse next is required"
oModel:BrowseNext() case aArgs[ 1 ] == "prev"
? "browse prev is required"
oModel:BrowsePrev() case aArgs[ 1 ] == "del"
? "del is required"
oModel:Delete()
endcase case cMethod == "POST"
? "We process a POST"
do case
case aArgs[ 1 ] == "save"
? "save is required"
oModel:Save()
endcase
endcasereturn nilfunction CheckTables() if ! File( hb_GetEnv( "PRGPATH" ) + "/links.dbf" )
DbCreate( hb_GetEnv( "PRGPATH" ) + "/links.dbf",;
{ { "LINKDEST", "C", 200, 0 },;
{ "LINKNAME", "C", 200, 0 },;
{ "LONGTEXT", "M", 10, 0 } } )
endif USE ( hb_GetEnv( "PRGPATH" ) + "/links" ) SHARED NEWreturn nilCLASS Model METHOD Add() VIRTUAL
METHOD Edit() VIRTUAL
METHOD BrowseNext() VIRTUAL
METHOD BrowsePrev() VIRTUAL
METHOD Delete() VIRTUAL
METHOD Save() VIRTUAL
ENDCLASS
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: mod harbour "SEAMAP"
Dear Antonio,
now I copied your code into my project but I get following error when I read the web page:
I also copied hbclass.ch from harbour to my seamap directory:
Error: Syntax error "syntax error at '_HB_MEMBER'"
operation: line:58
called from: ../../../apache.prg, (b)MAIN, line: 50
Can you please help me
Best regards
Otto
now I copied your code into my project but I get following error when I read the web page:
I also copied hbclass.ch from harbour to my seamap directory:
Error: Syntax error "syntax error at '_HB_MEMBER'"
operation: line:58
called from: ../../../apache.prg, (b)MAIN, line: 50
Can you please help me
Best regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: mod harbour "SEAMAP"
Dear Antonio,
your code before you add OOP works fine and I inserted a view.
I have a question how I can forward an ARRAY to the view modul.
In tBody of the view modul I do following:
<tbody>
<?prg local I := 0, cRow := "" //mod harbour code inside HTML TAG starts with <?prg
for I := 1 to len( alinks )
cRow += '<tr>'
cRow += '<th scope="row">' + ALLTRIM( str(I) ) + '</th>'
cRow += "<td><a target='_blank' href=" + alinks[I,1] + ">" + alinks[I,2] + "</a>"
cRow += '<br>'
cRow += alinks[I,3]
cRow += "</td>"
next
return cRow ?>
</tbody>
</table>
But I get following error:
Best regards
Otto
your code before you add OOP works fine and I inserted a view.
I have a question how I can forward an ARRAY to the view modul.
Code: Select all
alinks is a static ARRAY
function CheckTables()
if ! File( hb_GetEnv( "PRGPATH" ) + "/links.dbf" )
DbCreate( hb_GetEnv( "PRGPATH" ) + "/links.dbf",;
{ { "LINKDEST", "C", 200, 0 },;
{ "LINKNAME", "C", 200, 0 },;
{ "LONGTEXT", "M", 10, 0 } } )
endif
USE ( hb_GetEnv( "PRGPATH" ) + "/links" ) SHARED NEW
do while .not. eof()
aadd( alinks, { field->linkdest, field->linkname, field->longtext } )
skip
enddo
USE
return nil
<tbody>
<?prg local I := 0, cRow := "" //mod harbour code inside HTML TAG starts with <?prg
for I := 1 to len( alinks )
cRow += '<tr>'
cRow += '<th scope="row">' + ALLTRIM( str(I) ) + '</th>'
cRow += "<td><a target='_blank' href=" + alinks[I,1] + ">" + alinks[I,2] + "</a>"
cRow += '<br>'
cRow += alinks[I,3]
cRow += "</td>"
next
return cRow ?>
</tbody>
</table>
But I get following error:
Best regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: mod harbour "SEAMAP"
Hello all,
I am coping from SLACK to our forum.
I will format this later - this is so important information from Antonio showing how to use MVC that we should not lose.
from SLACK
https://mybergland.com/fwforum/fromslackmvc.txt
I am coping from SLACK to our forum.
I will format this later - this is so important information from Antonio showing how to use MVC that we should not lose.
from SLACK
https://mybergland.com/fwforum/fromslackmvc.txt
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: mod harbour "SEAMAP"
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************