config {
#    engine CGI;
    engine MP13;
    template_engine TT;
    Init Std {  }
    SQL SQLite {  }
    SQL Postgres {  }
    SQL MySQL {  }
#    CGI Gantry { gen_root 1; with_server 1; flex_db 1; gantry_conf 1; }
    HttpdConf Gantry { gantry_conf 1; }
    Control Gantry { dbix 1; }
    Model GantryDBIxClass {  }
    SiteLook GantryDefault {  }
    Conf Gantry { conffile `/etc/gantry.conf.2`; gen_root 1; instance jobad; }
}
app JobAd {
    config {
#        dbconn `dbi:SQLite:dbname=app.db` => no_accessor;
        dbconn `dbi:Pg:dbname=jobad.db` => no_accessor;
        dbuser postgres => no_accessor;
        root `/home/pcrow/srcgantry/docs/book/studies/JobAd/html/templates` => no_accessor;
        template_wrapper `genwrapper.tt` => no_accessor;
        auth_deny yes => no_accessor;
        auth_require `valid-user` => no_accessor;
    }
    controller is base_controller {
        method do_main is base_links {
        }
        method site_links is links {
        }
    }
    table job {
        field id {
            is int4, primary_key, auto;
        }
        field title {
            is varchar;
            label Title;
            html_form_type text;
        }
        field description {
            is varchar;
            label Description;
            html_form_type textarea;
            html_form_rows 6;
            html_form_cols 55;
        }
        field created {
            is datetime;
        }
        field modified {
            is datetime;
        }
        foreign_display `%title`;
        field travel_percent {
            is varchar;
            label `Travel Percent`;
            html_form_type text;
        }
        field on_site {
            is varchar;
            label `On Site`;
            html_form_type select;
            html_form_options
                `On-Site` => onsite,
                `Partial Telecommute` => parttele,
                Telecommute => tele;
        }
        field time_percent {
            is varchar;
            label `Time Percent`;
            html_form_type select;
            html_form_options
                `Full Time` => full,
                `Part Time` => part,
                Contract => con;
        }
    }
    controller Job is CRUD {
        controls_table job;
        rel_location job;
        text_description job;
        page_link_label Job;
        method do_main is main_listing {
            cols title, description;
            header_options Add;
            row_options Edit, Delete;
            title Job;
        }
        method job_form is CRUD_form {
            all_fields_but id, created, modified;
            extra_keys
                legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
    }
    table skill {
        field id {
            is int4, primary_key, auto;
        }
        field ident {
            is varchar;
            label Ident;
            html_form_type text;
        }
        field description {
            is varchar;
            label Description;
            html_form_type text;
        }
        field created {
            is datetime;
        }
        field modified {
            is datetime;
        }
        foreign_display `%ident`;
        data
            ident => drive,
            description => `Valid driver license and clean record`;
        data
            ident => coffee,
            description => `Ability to brew excellent coffee from bad grounds`;
        data
            ident => bigtop_exp,
            description => `5+ years bigtop experience`;
        data
            ident => bigtop,
            description => `Experience with bigtop`;
    }
    controller Skill is AutoCRUD {
        controls_table skill;
        rel_location skill;
        text_description skill;
        page_link_label Skill;
        method do_main is main_listing {
            cols ident, description;
            header_options Add;
            row_options Edit, Delete;
            title Skill;
        }
        method form is AutoCRUD_form {
            all_fields_but id, created, modified;
            extra_keys
                legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
        config {
            auth_require group;
            auth_groups HR;
        }
    }
    table position {
        field id {
            is int4, primary_key, auto;
        }
        field n_openings {
            is int4;
            label `N Openings`;
            html_form_type text;
            html_form_constraint `qr{^\d $}`;
        }
        field location {
            is varchar;
            label Location;
            html_form_type text;
        }
        field created {
            is datetime;
        }
        field modified {
            is datetime;
        }
        foreign_display `%n_openings`;
        field job {
            is int4;
            label Job;
            refers_to job;
            html_form_type select;
        }
        field closes {
            is date;
            label Closes;
            html_form_type text;
            date_select_text `Select Date`;
        }
        field boss {
            is varchar;
            label Boss;
            html_form_type text;
        }
        field pay {
            is varchar;
            label Pay;
            html_form_type text;
        }
    }
    controller Position is AutoCRUD {
        controls_table position;
        rel_location position;
        text_description position;
        page_link_label Position;
        method do_main is main_listing {
            cols n_openings, location;
            header_options Add;
            row_options Edit, Delete;
            title Position;
        }
        method form is AutoCRUD_form {
            all_fields_but id, created, modified;
            extra_keys
                legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`,
                javascript => `$self->calendar_month_js( 'position' )`;
            form_name position;
        }
        uses Gantry::Plugins::Calendar;
    }
    join_table job_skill {
        joins job => skill;
    }
    table user {
        field id {
            is int4, primary_key, auto;
        }
        field ident {
            is varchar;
            label Ident;
            html_form_type text;
        }
        field password {
            is varchar;
            label Passwd;
            html_form_type text;
        }
        field created {
            is datetime;
        }
        field modified {
            is datetime;
        }
        foreign_display `%ident`;
        field first_name {
            is varchar;
            label `First Name`;
            html_form_type text;
        }
        field last_name {
            is varchar;
            label `Last Name`;
            html_form_type text;
        }
        field email {
            is varchar;
            label Email;
            html_form_type text;
        }
        data
            ident => pcrow,
            first_name => Phil,
            last_name => Crow,
            password => test;
        data
            ident => lcrow,
            first_name => Lisa,
            last_name => Crow,
            password => test;
    }
    controller User is AutoCRUD {
        controls_table user;
        rel_location user;
        text_description user;
        page_link_label User;
        method do_main is main_listing {
            cols ident, password;
            header_options Add;
            row_options Edit, Delete;
            title User;
        }
        method form is AutoCRUD_form {
            all_fields_but id, created, modified;
            extra_keys
                legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
    }
    table grouping {
        field id {
            is int4, primary_key, auto;
        }
        field ident {
            is varchar;
            label Ident;
            html_form_type text;
        }
        field description {
            is varchar;
            label Description;
            html_form_type text;
        }
        field created {
            is datetime;
        }
        field modified {
            is datetime;
        }
        foreign_display `%ident`;
        data
            ident => HR,
            description => `Human Resources Staff`;
    }
    controller Grouping is AutoCRUD {
        controls_table grouping;
        rel_location grouping;
        text_description grouping;
        page_link_label Grouping;
        method do_main is main_listing {
            cols ident, description;
            header_options Add;
            row_options Edit, Delete;
            title Grouping;
        }
        method form is AutoCRUD_form {
            all_fields_but id, created, modified;
            extra_keys
                legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
    }
    join_table user_grouping {
        joins user => grouping;
        names users => groups;
    }
    literal SQL
      `INSERT INTO user_grouping ( user, grouping ) VALUES ( 1, 1 );`;
    table change_log {
        field id {
            is int4, primary_key, auto;
        }
        field ident {
            is varchar;
            label Ident;
            html_form_type text;
        }
        field description {
            is varchar;
            label Description;
            html_form_type text;
        }
        field created {
            is datetime;
        }
        field modified {
            is datetime;
        }
        foreign_display `%ident`;
        field user {
            is int4;
            label User;
            refers_to user;
            html_form_type select;
        }
    }
}
