
! script name: archive.d/dirinfotable
! topic: make a table from the information in a directory of projects.

!A
!A NAME:
!A
!A	Directory Information Table
!A
!A DESCRIPTION:
!A
!A	Make a table from the data in a directory.
!A
!# see also - htdocs/help.d/archive.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: directory table")

DIM Answer$[256],Destination$[256]
DIM Archive$[512]
DIM Project$[512]
DIM Project_dir$[512]
DIM Archive_dir$[512]
DIM Current_dir$[512]
DIM Filename$[512]
DIM Last_rev$[512]
DIM Prefix$[256]
DIM Choice$[256]
DIM Ques$[256]
DIM D_label$[256]
DIM Table_name$[512]
DIM Table_title$[512]

DeActivateUndo
Html_table= 0
IF ARGC > 1 THEN
        Answer$= ARGV(1)
        Html_table= VAL(Answer$)
END IF
Table_name$= "ARCHIVE DIRECTORY TABLE"
Table_title$= "ARCHIVE DIRECTORY TABLE"

Stat= NamedVarStr("archive dir",WsSystemVars,"/usr/weber/archive/",Archive$)

Grid_color= 18
Entry_color= 12
Entry_text_height= GetDefault(WsTextHeight)
Entry_text_width= GetDefault(WsTextWidth)

Header_color= 17
Head_text_height= 1.2*Entry_text_height
Head_text_width= 1.2*Entry_text_width
Header_slant= TAN(20)

IF NOT DoesFileExist(Archive$) THEN Leave
Archive_dir$= Archive$
Prefix$= "revision"

Project_dir:!
Ques$= "SELECT DIRECTORY   Select this one "
D_label$= "PROJECTS"
Choice$= "selected directory"
Answer$= SelectDirectory(Archive_dir$,"*",Ques$,D_label$,Choice$,Prefix$,Current_dir$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "New", "CANCEL"
        GOTO Leave
CASE "Select"
        Project_dir$= Current_dir$
CASE ELSE
        Answer$= TRIM$(Answer$)
        Project_dir$= PathNameDirectory(Answer$)
END SELECT


IF NOT DoesFileExist(Project_dir$) THEN Project_dir
Last_rev$=FileNameString(Project_dir$,"dinfo.txt")
DirInfo= ReadUserData(WsArchiveFileInfo,"Directory information",Last_rev$)
Group= CreateGroup("directory data")
Stat= AddToGroup(Group,DirInfo)

Table_pos:!
IF Html_table THEN
        Pc= PointXYZ(0,0,0)
ELSE
        Stat=SetInputFormat("n4","")
        Pc=XyzInput("TABLE LOCATION ",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pc) THEN Table_pos
END IF

Table1= FindNamedEntity(Table_name$)
IF Table1 THEN Stat= DeleteEntity(Table1)


PlotOff
Table1= TableFromPropGrp(Group,Pc,":",WsUpperLeft)
Stat= DeleteEntity(Pc)
Stat= DeleteGroup(Group,WsTrue)

Set_table_props:!
Stat= TableTextOrigin(Table1,1,0,WsCenterText)
Stat= SetTableColors(Table1,0,0,Entry_color)
Stat= SetTableColors(Table1,1,0,Header_color)
Stat= TableTextSizes(Table1,1,0,Head_text_width,Head_text_height,Header_slant)
Stat= SetColor(Table1,Grid_color)
Stat= NameEntity(Table1,Table_name$)

Stat= TransposeTable(Table1)
PlotOn
Stat= DeleteEntity(DirInfo)
Stat= DeleteEntity(Group)
LowerSelectBox

IF Html_table THEN
        LOAD "datatable.d/exporthtml: 0,"&Table_name$&",1,"&Table_title$
ELSE
        Stat= PlotEntity(Table1)
END IF


GOTO Project_dir


Leave:!
PlotOn
stat= DeleteEntity(Group)
stat= DeleteEntity(DirInfo)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
