The Front End
October 9, 2000
In a local source control system (i.e., one that is not distributed
across the internet), a visual front end might not be necessary.
Whenever a user opens a file, the system could automatically check
the file out, and assign the necessary attributes to ensure that
no one else edits the file at the same time. If someone else
tries to open the file at the same time, they could be stopped.
However, when the source files are all located away from the users
(i.e. a web server), then we must build a front end for users
to check files in and out, and perform other tasks.
For example's sake, let's assume our two databases are filled with
the following data:
|
tblFiles |
|
tblDirectories |
| FID |
Name |
Parent - FolderID |
User |
LastModified |
Location |
|
DID |
Name |
Parent - FolderID |
1 2 3 4 5 |
index.asp
includes.asa go.gif blah.txt changes.html |
2 3 4 1 5
|
- - - - -
|
10/03/00 10:31AM 10/03/00 10:31AM
10/03/00 10:31AM 10/03/00 10:31AM 10/03/00 10:31AM
|
c:\top\html
c:\top\html\scripts c:\top\html\images c:\top\TempFolder c:\top
|
|
1 2 3 4 5 |
Top HTML Scripts
Images TempFolder |
0 1 2 2 1 |
Which would produce a hierarchy tree like the following:
<Top>
|-<HTML>
| |-<Scripts>
| | |- includes.asa
| |-<Images>
| | |- go.gif
| |- index.asp
|-<TempFolder>
| |- changes.html
|-blah.txt
The first thing you'll want to display to the user is the above
hierarchy tree. Here's the ASP to do so:
<%
call PrintTree(0) <-- Print the hierarchy tree from the top
Sub PrintTree(intDID)
dim strSQL, rst, strConnectionString
'Set database variables
strConnectionString = "DSN=MySource;UID=username;PWD=password;Database=MySourceDB"
set rst = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT Name, DID FROM tblDirectories WHERE ParentFolderID = "
& intDID
rst.open strSQL, strConnectionString
while not rst.eof
Response.write("|-<" & rst(0) & "><br>"
call PrintTree(rs(1))
wend
rst.close
strSQL = "SELECT Name, FID FROM tblFiles WHERE ParentFolderID = "
& intDID & " ORDER BY Name"
rst.open strSQL, strConnectionString
while not rst.eof
Response.write("|-" & rst(0) & "<br>")
wend
rst.close
set rst = nothing
End Sub
%>
The key to the above code is the recursive sub routine, PrintTree
(See
4GuysFromRolla for a tutorial on recursion). This sub routine
loops through all the sub-folders and files for each folder, and prints
out the name and tree structure similar to structure outlined above.
This is great to let the users see the data structure, but other
than that, it's practically useless as is.
Once the users see the file structure, they have to select files they
wish to manipulate (check out, check in, etc). Let's modify the
above function a bit - we'll change the Response.writes,
and add another parameter to the call:
<%
strUser = Session("User") <-- Get the logged on user's identity
call PrintTree(0, strUser)
Sub PrintTree(intDID, Username) <--Added parameter
...
...
strSQL = "SELECT Name, FID, User FROM tblFiles WHERE ParentFolderID = "
& intDID & " ORDER BY Name"
rst.open strSQL, strConnectionString
while not rst.eof
if strComp(rst(2), strUser) = 0 then
Response.write("|-<input type=""checkbox"" name=""file"" " & _
"value=" & rs(1) & " CHECKED><b>" & rst(0) & "</b><br>")
elseif rst(2) <> "" then
Response.write("|-<input type=""checkbox"" name=""file"" " & _
"value=" & rs(1) & " CHECKED DISABLED>" & rst(0) & "<br>")
else
Response.write("|-<input type=""checkbox"" name=""file"" " & _
"value=" & rs(1) & " >" & rst(0) & "<br>")
end if
wend
...
...
End Sub
%>
We've changed a few things here. First, we added checkboxes
next to the file names so that the users can select files to
manipulate. Second, if the user who is currently
logged in (you must make a separate ASP page to log users in),
has a file checked out, then that file will be prechecked and in
bold. Next, if any file is already checked out, and the current
user is not the checkee, then we must not let the user check that
file out. Therefore, we precheck it, and disable it as well.
Finally, if a file is not checked out at all, then simply show
the checkbox so that the user can select it. (Note that you must
also build the
form
tags and check in/check out buttons, which are
not shown
here.)
|
NOTE:
In these examples, we have used "|-" to form the backbone
of the hierarchy tree, but you may use anything you wish,
including images of folders.
|
The Database
Effective Source Control
Continuing On...
|