Welcome to forager.com a foragers site.

Comserv Application Documentation

Back to top of Documentation

Overview

Main Features of the New Site:

  1. AI Integration with the Site:

    Integrates the ability to search internal resources, external resources, and add information to the local system.
  2. Modular Design:

    Ensures the site is built in a modular fashion for ease of maintenance and scalability.
  3. ToDo, Project Management, Logs:

    Incorporates tools for managing tasks, projects, and maintaining logs for better tracking and management.
  4. Admin Functions:

    Provides capabilities to edit files, control Cascading Style Sheets, update the application, and manage the schema.
  5. Security:

    Implements robust security measures to protect data and user information.
  6. Documentation:

    Maintains comprehensive documentation to assist developers and users.
  7. Uses Artificial Intelligence to build a comprehensive information base, improving search accuracy and relevance.
  8. Reference System of Documents:

    Offers a well-organized system for managing and referencing documents.
  9. Power Monitoring System:

    Includes a system for monitoring power usage and efficiency.
  10. Web-Based Email:

    Provides a web-based email client for managing emails.
  11. Web-Based Calendar:

    The application now includes a web-based calendar module. This module can be used by all other modules in the application for scheduling and event management. It provides features such as creating, viewing, and editing events, setting reminders, and sharing events with other users. The calendar module is designed to be flexible and adaptable, allowing it to be integrated with other modules in various ways. For example, the project management module could use the calendar to schedule project deadlines and milestones, while the education module could use it to schedule classes and exams.
  12. Web-Based Address Book:

    Maintains a web-based address book for contact management.
  13. Web-Based File Manager:

    Includes a web-based file manager for file storage and organization.
  14. Web-Based Photo Album:

    Provides a web-based photo album for managing and sharing photos.
  15. Web-Based Music Player:

    Includes a web-based music player for playing and managing music files.
  16. Hosting Multiple Sites:

    Supports the ability to host multiple sites using the same software.
  17. Extensive Herbal and Health Information:

    Provides detailed information on herbs and health-related topics.

Back to top of Main Features

Suggestions for Improvement and Expansion

Instructions for Developers

To ensure the continuous improvement and consistency of this project, please adhere to the following guidelines:

We are committed to evolving the Comserv application to meet the needs of our users. Your contributions and adherence to these guidelines are crucial for our continued success.

Back to top of Overview

Back to top of Documentation

Admin Module

Table of Contents

The Admin module provides a suite of tools for managing various aspects of the site, with a current focus on handling schema changes within the application.

Site Management

The Site Management section includes the following features:

Database Schema Management

The Database Schema Management section focuses on managing database schema changes from within the application. It includes the following features:

For more information on how to use these features, please refer to the specific documentation for each feature.

Back to top of Documentation

AI Integration Plan

This document outlines the integration of AI features into the Comserv application, focusing on enhancing user interactions and data management.

Objectives

Implementation Steps

  1. Research and select appropriate AI frameworks and libraries.
  2. Integrate AI components into the existing architecture.
  3. Test AI functionalities in a controlled environment.
  4. Deploy AI features in production and monitor performance.

Future Enhancements

Explore additional AI capabilities such as predictive analytics and automated content generation.

Back to top of Documentation

DBI Setup

DBI (Database Independent Interface) is a database access module for the Perl programming language. It defines a set of methods, variables, and conventions that provide a consistent database interface, independent of the actual database being used.

In the `Comserv::Model::DBEncy` and `Comserv::Model::DBForager` modules, DBI is used to establish connections to the respective MySQL databases ('Ency' and 'Forager').

The database connection information for each module is retrieved from a JSON file named 'db_config.json', which contains details such as the database name, host, port, username, and password.

The `_build_dbh` method in each module is responsible for establishing the database connection using the DBI->connect method.

Database Operations

The `DBEncy` and `DBForager` modules provide methods for performing various database operations specific to their respective MySQL databases.

Debugging

The code includes extensive debugging output, with print statements showing the progress of execution and the values of important variables. This can be very helpful for troubleshooting problems with database operations.

Security

The code employs security measures such as hashing passwords using the Digest::SHA module to ensure secure password storage.

Catalyst Integration

The `DBEncy` and `DBForager` modules are designed to be used as models in a Catalyst application. They utilize the Catalyst context object ($c) to access session data and other Catalyst features.

For more information on how AI can enhance the functionalities of the DBI module, refer to the AI Integration Plan.

Back to top of Documentation

Beemaster Application.

This application is intended to both educate and provide a platform for beekeepers to manage their hives and apiaries

We have added several links to the main page of the application most are described in the controller. The latest addition to the application is the return of access to the old database table for herbs that from the point of view of BMaster is the Bee pasture view. The BeePastureView give a current list of all the plants that are used by pollinators as pasture.

searchHerbs

The search field now works if the search string appears in the record it is returned. to the browser in a list. The details link pulls all the data in the table.

Please look to the ency module for details on how this works.

The 'searchHerbs' function in the 'Comserv/lib/Comserv/Model/DBForager.pm' file has been updated to improve the search functionality in the BMaster system. The function now uses normalized field names that match the field names in the database and the view. It also stores all debug messages in an array and puts that array into the stash, allowing all debug messages to be passed to the template and displayed in the browser. In the case where no records are returned from the search, a specific debug message stating "No results found" is added to the debug messages array.

Back to top BMaster

BMaster Controller Documentation

base

The 'base' function is the root of the chained actions in the BMaster controller. It captures '/BMaster' in the URL and performs common setup tasks that are shared by multiple actions in the controller. Here are some examples of what the 'base' function can do:

By performing these common setup tasks in the 'base' function, we can avoid duplicating code in multiple actions, making the code more maintainable and easier to understand.

index

This function sets the template to 'BMaster/BMaster.tt' and forwards to the TT view.

frames

This function gets the frames for the given queen and sets the template to 'BMaster/frames.tt'.

api_frames

This function fetches the data for the frames and sets the response body to the JSON representation of the data.

products

This function sets the template to 'BMaster/products.tt'.

yards

This function gets the yards and sets the template to 'BMaster/yards.tt'.

apiary

This function sets the template to 'BMaster/apiary.tt'.

queens

This function sets the template to 'BMaster/Queens.tt'.

hive

This function sets the template to 'BMaster/hive.tt'.

honey

This function sets the template to 'BMaster/honey.tt'.

beehealth

This function sets the template to 'BMaster/beehealth.tt'.

environment

This function sets the template to 'BMaster/environment.tt'.

education

This function sets the template to 'BMaster/education.tt'.

Back to top BMaster

BMaster Model Documentation

get_frames_for_queen

This function fetches the frames for a given queen based on the queen's tag number. It returns a reference to an array of frames.

get_yards_for_site

This function fetches all yards for a given site based on the site's name. It returns a reference to an array of yards.

Back to top BMaster

Queen Management System

Our queen management system is designed to manage the lifecycle of the queen bees in our apiary. Here are the key activities and their timelines:

Date Activity
Graft date The date when the grafting process starts.
3 days after graft date Move the brood back from the incubator and count the number of cells that have been started.
10 days after graft date Move the cells to the mating nucs.
20 days after graft date The queen will have been mated and start laying.
Queen pull The number of days entered in the form egg laying day.
Second graft Done 10 days before the queen pull.

We store the graft date and the number of days of egg laying in the database. This helps us to track and manage the lifecycle of each queen bee.

Back to top of Documentation

Calendar Module:

Overview:

The Calendar module is a web-based calendar that can be used by all other modules in the application for scheduling and event management. It provides features such as creating, viewing, and editing events, setting reminders, and sharing events with other users.

Features:

The Calendar module provides the following features:

Usage:

Here's how to use the Calendar module:

Development Plan:

Here's a detailed plan for the development of the calendar module in Catalyst:

1. Database Schema:

Define a database schema for the calendar events. This schema will be used to create a table in your database. The table includes fields such as `event_id`, `event_name`, `start_date`, `end_date`, `description`, `location`, `organizer`, `attendees`, `status`, `last_modified_by`, `last_mod_date`, and `user_id`.

To create this schema, you can use the Catalyst helper scripts. Here are the steps:

  1. First, create a new Catalyst model using the `comserv_create.pl` script. This script will generate a new model class in your application. For example:
  2.     script/comserv_create.pl model Calendar DBIC::Schema Comserv::Schema::Ency::Result create=static `perl -MComserv::Model::DBEncy -e 'print Comserv::Model::DBEncy->config->{connect_info}->{dsn}'`
        

    In this command, `Calendar` is the name of the model, `DBIC::Schema` specifies that we're creating a DBIx::Class schema, `Comserv::Schema::Ency::Result` is the namespace of the schema, `create=static` tells the script to create a static schema, and the Perl one-liner is used to retrieve the DSN from `DBEncy.pm`.

  3. Next, define your schema in the generated model class. Here's an example:
  4.     package Comserv::Model::Schema::Ency::Result::Event;
    
        use base 'DBIx::Class::Core';
    
        __PACKAGE__->table('event');
        __PACKAGE__->add_columns(
            event_id => {
                data_type => 'integer',
                is_auto_increment => 1,
            },
            event_name => {
                data_type => 'varchar',
                size => 255,
            },
            start_date => {
                data_type => 'date',
            },
            end_date => {
                data_type => 'date',
            },
            description => {
                data_type => 'text',
            },
            location => {
                data_type => 'varchar',
                size => 255,
            },
            "organizer",
            { data_type => "varchar", default_value => "", is_nullable => 1, size => 50 },
            "attendees",
            { data_type => "text", is_nullable => 1 },
            status => {
                data_type => 'varchar',
                size => 255,
            },
            "last_modified_by",
            { data_type => "varchar", default_value => "", is_nullable => 1, size => 50 },
            last_mod_date => {
                data_type => 'date',
            },
            user_id => {
                data_type => 'integer',
            },
        );
        __PACKAGE__->set_primary_key('event_id');
        __PACKAGE__->belongs_to(user => 'Comserv::Model::Schema::Ency::Result::User', 'user_id');
        

    This code defines an `event` table with fields such as `event_id`, `event_name`, `start_date`, `end_date`, `description`, `location`, `organizer`, `attendees`, `status`, `last_modified_by`, `last_mod_date`, and `user_id`.

  5. Finally, use the `deploy` method on your schema object to create the table in your database. For example:
  6.     my $schema = $c->model('Calendar')->schema;
        $schema->deploy;
        

    This code should be run in a script or controller action that has access to your Catalyst context (`$c`).

To create the table directly in the database using SQL, you can use the following SQL command:

```sql CREATE TABLE event ( event_id INT PRIMARY KEY AUTO_INCREMENT, event_name VARCHAR(255), start_date DATE, end_date DATE, description TEXT, location VARCHAR(255), organizer VARCHAR(50), attendees TEXT, status VARCHAR(255), last_modified_by VARCHAR(50), last_mod_date DATE, user_id INT, FOREIGN KEY (user_id) REFERENCES User(user_id) );

2. Catalyst Model (Calendar.pm):

We have created a Catalyst model named `Calendar` that extends `Comserv::Model::DBEncy` and adds custom methods to interact with the Calendar related tables. Currently, it has a method `get_events` that fetches events from the 'Event' table that match a given search criteria.

3. Catalyst Controller (Calendar.pm):

Create a Catalyst controller with actions for creating, reading, updating, and deleting events.

4. Catalyst View (Calendar.tt):

Create a Catalyst view to display the events in a calendar format.

5. Authentication and Authorization:

Use the existing `User` and `Admin` modules to handle authentication and authorization. If necessary, restrict access to certain actions (for example, only logged-in users can create events).

6. Prebuilt Applications:

There are several Perl modules on CPAN that might be useful. `Data::ICal` can generate iCalendar files, and `DateTime::Event::ICal` can calculate dates based on iCalendar recurrence rules.

Please note that this is a high-level plan and the actual implementation might require additional steps or modifications.

Back to top of Documentation

Document Management

Back to top of Commandment Management

Documentation/DBIDocument.tt,v 0.03 2025/01/02 Shanta Exp shanta

DBI Setup for AutoCRUD Integration

With the integration of `Catalyst::Plugin::AutoCRUD`, we enhance our database operations by providing an automatic CRUD interface for managing content within our Catalyst application, 'Comserv'.

AI features will further enhance the capabilities of AutoCRUD, allowing for intelligent data management and user interactions.

Integration Plan for AutoCRUD

Step 1: Setup & Configuration

Step 2: Database Schema Migration

Step 3: Implement CRUD Operations

Step 4: Testing & Deployment

Step 5: Update Documentation & Training

Debugging

Continue using the existing debugging setup, and add AutoCRUD-specific debugging where necessary.

Security

Ensure that security measures are maintained or enhanced, particularly focusing on data integrity and access control with the new schema setup.

Catalyst Integration

The `DB::PageSchema` module now integrates with Catalyst to manage page content through AutoCRUD, using the Catalyst context for session management and other features.

For further enhancements using Artificial Intelligence (AI), please refer to the AI Integration Plan.

Back to top of Documentation

ENCY Module

ENCY Controller

The ENCY controller is responsible for handling requests related to the ENCY model. It includes several subroutines, each of which performs a specific task.

Return to top

index

The index subroutine handles requests to the root of the ENCY controller's URL. It sets the template to 'ENCY/index.tt', which is used to render the response.


sub index :Path('/ENCY') :Args(0) {
    my ( $self, $c ) = @_;
    # The index action will display the 'index.tt' template
    $c->stash(template => 'ENCY/index.tt');
}

Return to top

botanical_name_view

The botanical_name_view subroutine handles requests to display the Botanical Name View page. It fetches herbal data from the 'DBForager' model and passes this data to the template.


sub botanical_name_view :Path('/ENCY/BotanicalNameView') :Args(0) {
    my ( $self, $c ) = @_;

    # Fetch the herbal data
    my $forager_data = $c->model('DBForager')->get_herbal_data();

    # Pass the data to the template
    my $herbal_data = $forager_data;
    $c->stash(herbal_data => $herbal_data, template => 'ENCY/BotanicalNameView.tt');
}

Return to top

herb_detail

The herb_detail subroutine handles requests to display detailed information about a specific herb. It takes an id as an argument, fetches the corresponding herb from the 'DBForager' model, and sets the herb and the template 'ENCY/HerbDetailView.tt' in the stash.


sub herb_detail :Path('/ENCY/herb_detail') :Args(1) {
    my ( $self, $c, $id ) = @_;
    my $herb = $c->model('DBForager')->get_herb_by_id($id);
    $c->stash(herb => $herb, template => 'ENCY/HerbDetailView.tt');
}

Return to top

get_reference_by_id

The get_reference_by_id subroutine handles requests to get a reference by its id. It takes an id as an argument, fetches the corresponding reference from the 'ENCY' model, and sets the reference and the template 'ency/get_reference_form.tt' in the stash.


sub get_reference_by_id :Local {
    my ( $self, $c, $id ) = @_;
    # Fetch the reference using the ENCY model
    my $reference = $c->model('ENCY')->get_reference_by_id($id);
    $c->stash(reference => $reference);
    $c->stash(template => 'ency/get_reference_form.tt');
}

Return to top

create_reference

The create_reference subroutine handles requests to display the form for creating a new reference. It sets the template 'ency/create_reference_form.tt' in the stash.


sub create_reference :Local {
    my ( $self, $c ) = @_;
    # Display the form for creating a new reference
    $c->stash(template => 'ency/create_reference_form.tt');
}

Return to top

get_category_by_id

The get_category_by_id subroutine handles requests to get a category by its id. It takes an id as an argument, fetches the corresponding category from the 'ENCY' model, and sets the category and the template 'ency/get_category_form.tt' in the stash.


sub get_category_by_id :Local {
    my ( $self, $c, $id ) = @_;
    # Fetch the category using the ENCY model
    my $category = $c->model('ENCY')->get_category_by_id($id);
    $c->stash(category => $category);
    $c->stash(template => 'ency/get_category_form.tt');
}

Return to top

For more information on how AI can enhance the functionalities of the ENCY module, refer to the AI Integration Plan.

create_category

The create_category subroutine handles requests to display the form for creating a new category. It sets the template 'ency/create_category_form.tt' in the stash.


sub create_category :Local {
    my ( $self, $c ) = @_;
    # Display the form for creating a new category
    $c->stash(template => 'ency/create_category_form.tt');
}

Return to top

Each of these subroutines relies on the ENCY model to perform its tasks. The ENCY model is loaded in the ENCY controller with the use Comserv::Model::ENCY; statement. The ENCY model is defined in the 'Comserv::Model::ENCY' package, which is located in the 'lib/Comserv/Model' directory.

Return to top

Future Development

To evolve the ENCY application, consider the following enhancements:

ENCY Model

ENCY Model

The ENCY model is responsible for handling data related to the ENCY controller. It includes several methods, each of which performs a specific task.

Return to top

get_reference_by_id

The 'get_reference_by_id' method is responsible for fetching a reference by its id. It takes an id as an argument, fetches the corresponding reference from the database, and returns the reference.

Return to top

create_reference

The 'create_reference' method is responsible for creating a new reference. It takes the necessary data as arguments, creates a new reference in the database, and returns the new reference.

Return to top

get_category_by_id

The 'get_category_by_id' method is responsible for fetching a category by its id. It takes an id as an argument, fetches the corresponding category from the database, and returns the category.

Return to top

create_category

The 'create_category' method is responsible for creating a new category. It takes the necessary data as arguments, creates a new category in the database, and returns the new category.

Return to top

Each of these methods is used by the ENCY controller to perform its tasks. The ENCY model is defined in the 'Comserv::Model::ENCY' package, which is located in the 'lib/Comserv/Model' directory.

Return to top

Controller |

Back to top of Documentation

Files

To handle file uploads from multiple users and ensure that each user can only access their own uploaded files, you can follow these steps:

  1. When a user uploads a file, save the file in a user-specific directory. The directory can be named after the user's unique ID or username to ensure it's unique for each user.
  2. When serving files, check if the requested file is in the directory corresponding to the currently logged-in user. If it is, serve the file. If not, return an error or redirect the user.
  3. setfacl -m u:starman_user:rwx /path/to/user/directory/starman Yes, you can automate the process of creating the directory and setting its permissions when a new user is created in Virtualmin. You can do this by adding a script to the "Post-creation script" field in the Server Templates settings. Here's a basic example of what the script could look like: ```bash #!/bin/bash # Create the directory mkdir -p /home/${USER}/public_html/starman # Set the permissions setfacl -m u:starman_user:rwx /home/${USER}/public_html/starman ``` This script will create a 'starman' directory in the 'public_html' directory of the new user's home directory and then set the necessary permissions for the 'starman_user'. Please replace 'starman_user' with the actual username of the user under which the Starman server is running. To add this script to the Server Template: 1. Go to Virtualmin > System Settings > Server Templates. 2. Select the template you want to modify. 3. In the Edit Server Template page, find the "Post-creation script" field under the "Actions upon server and user creation" section. 4. Enter the full path to your script in this field. Now, whenever a new virtual server is created using this template, the script will be executed. Remember to make your script executable by running `chmod +x /path/to/your/script.sh`. Please note that this is a basic example and you might need to adjust it according to your specific needs and environment.
  4. Here's how you can modify the `handle_upload` method in the `Comserv::Model::File` model to implement this: ```perl5 sub handle_upload { my ($self, $c, $upload) = @_; # Extract the file's name and size my $filename = $upload->filename; my $filesize = $upload->size; # Define the allowed file types and maximum file size my @allowed_types = ('.jpg', '.png', '.pdf'); # adjust as needed my $max_size = 10 * 1024 * 1024; # 10 MB # Check the file type my ($file_type) = $filename =~ /(\.[^.]+)$/; unless (grep { $_ eq $file_type } @allowed_types) { return "Invalid file type. Allowed types are: " . join(", ", @allowed_types); } # Check the file size if ($filesize > $max_size) { return "File is too large. Maximum size is $max_size bytes."; } # Get the user's unique ID or username my $user_id = $c->user->id; # adjust this line to match your authentication system # Create a directory for the user if it doesn't exist my $directory = "uploads/$user_id"; unless (-d $directory) { mkdir $directory or return "Failed to create directory: $!"; } # Create the full path for the new file my $filepath = "$directory/$filename"; # Save the uploaded file my $result = $upload->copy_to($filepath); return $result ? "File uploaded successfully." : "Failed to upload file."; } ``` This code will save each user's uploaded files in a separate directory. When serving files, you would use a similar approach to check if the requested file is in the directory corresponding to the currently logged-in user. To implement access control in a Catalyst application, you can create a method in your controller that checks if the requested file is in the directory corresponding to the currently logged-in user. If it is, serve the file. If not, return an error or redirect the user.
  5. Here's a basic example of how you might implement this in your `Comserv::Controller::File` controller: ```perl5 sub serve_file :Local { my ($self, $c, $filename) = @_; # Get the user's unique ID or username my $user_id = $c->user->id; # adjust this line to match your authentication system # Create the full path for the requested file my $filepath = "uploads/$user_id/$filename"; # Check if the file exists and is readable if (-f $filepath && -r _) { # Serve the file $c->res->header('Content-Type' => 'application/octet-stream'); $c->res->body(scalar read_file($filepath, binmode => ':raw')); } else { # Return an error or redirect the user $c->res->status(403); # Forbidden $c->res->body('You do not have permission to access this file.'); } } ``` In this example, the `serve_file` method is a new action in your `Comserv::Controller::File` controller. It gets the requested filename from the URL, constructs the full path to the file based on the currently logged-in user's ID, and checks if the file exists and is readable. If it is, it serves the file to the user. If not, it returns a 403 Forbidden error. This is a very basic example and doesn't include any error handling or security measures. In a real application, you would want to add checks to ensure the filename is safe to use in a file path, the user is authenticated, and the user has permission to access the file.

Back to top of Documentation

Comserv Development Guidelines

Patch Format

When providing code returns, always use the `+-` patch format to prevent overwriting existing functions. This ensures that changes are clear and maintainable.

Catalyst Coding Standards

Follow these standards when coding in Catalyst:

Testing Guidelines

Ensure that your code is thoroughly tested, including testing for both .tt templates and the underlying code. Some key points to consider:

Back to top

Documentation Standards

Keep the documentation up-to-date and comprehensive. Ensure that all changes to the codebase are reflected in the corresponding documentation sections.

Back to top

Git Workflow

A Git workflow refers to the agreed-upon process for how developers should use Git to manage code changes, collaborate on features, and maintain the codebase. The key elements of the recommended Git workflow for this project are:

Follow the established Git workflow for the project, including regular commits with meaningful messages and the use of feature branches for new developments.

Back to top

Back to top

Security Guidelines

Back to top

Completed Items

Session Planning

When planning your sessions, please follow these guidelines:

  1. Please read sessionplan.tt.
  2. Compare the current prompt and the plan you would create for it with the session plan.
  3. Modify the current session plan to incorporate the plan you just created.

Example Prompt

When reminding the assistant, you can say: "Please follow the guidelines outlined in guidelines.tt, especially regarding the `+-` patch format for code returns and the prohibition on using placeholders in code returns."

Back to top of Documentation

Git Usage Guide for PyCharm

PyCharm Git Integration

  1. Enable Version Control:
  2. Commit Changes:

Common Workflows

Adding New Features to Production

  1. Create a New Branch:
    git checkout -b feature/forager-controller
  2. Add and Commit Changes:
    git add Forager.pm
    git commit -m "Add Forager controller for handling forager.com routes"
  3. Push to Remote:
    git push origin feature/forager-controller
  4. Deploy to Staging for Testing:
  5. Merge to Development/Staging:
  6. Final Test on Staging:
  7. Merge to Production:
    git checkout production
    git merge development
    git push origin production
  8. Monitor Post-Deployment:

Remove .idea Directory from a Git Branch

  1. Fetch the branch from the remote repository:

    git fetch origin branch_name:branch_name
  2. Remove the .idea directory from your local working directory:

    rm -rf .idea
  3. Switch to the fetched branch:

    git checkout branch_name
  4. Remove the .idea directory and commit the change:

    git rm -r .idea
    git commit -m "Remove .idea directory"
  5. Push the changes to the remote branch:

    git push origin branch_name

Replace branch_name with the name of the branch you want to remove the .idea directory from.

Troubleshooting Common Issues

Back to top of Documentation

Installation Guide

Module Installation with Perlbrew

  1. Switch to Perl 5.40.0:
    perlbrew switch perl-5.40.0
  2. Ensure PATH includes Perlbrew's bin:
    echo $PATH
    Ensure `/home/comserv/perl5/perlbrew/bin` and `/home/comserv/perl5/perlbrew/perls/perl-5.40.0/bin` are included.
  3. Set up local::lib for user-level installations:
    cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5 -Mlocal::lib)
    Add this to your shell configuration file (e.g., `.bashrc` or `.zshrc`) for persistence across sessions.
  4. Check Perl library paths:
    perl -e 'print join "\n", @INC'
    Verify paths like `/home/comserv/perl5/perlbrew/perls/perl-5.40.0/lib/site_perl/5.40.0` are listed.
  5. Install Dependencies from cpanfile:
    cpanm --installdeps .
    This command reads your `cpanfile` and installs all listed dependencies
  6. Create a directory for Comserv:
    mkdir /path/to/Comserv
  7. Clone the repository into the created directory:
    git clone git@github.com:comserv2/Comserv.git /path/to/Comserv
  8. Navigate to the cloned directory:
    cd /path/to/Comserv
  9. Install required modules from cpanfile:
    cpan
        
  10. Install required modules using cpanfile:
    cd /path/to/Comserv
    cpanm --installdeps .
  11. Verify installations:
    perl -MModule::Name -e 'print $Module::Name::VERSION'

Remember to always test each step in a safe environment before applying them to the production server.

Back to top of Documentation

Login System Documentation

Overview

The Login system is responsible for authenticating users and managing their sessions within the application. It ensures secure access to the system's features and data.

Controller

The Comserv::Controller::Login module handles the routing and logic for login-related actions:

Model

The Comserv::Model::Login module provides methods for interacting with user authentication data:

Templates

The following templates are used in the Login system:

Workflow

The typical workflow for user login involves displaying the login form, processing user credentials, and managing session states. The system provides feedback through success and error messages to guide the user through the login process.

Back to top

Back to top of Documentation

Logging

We currently have two separate logging systems:

Controller

The Comserv::Controller::Log module handles the routing and logic for log-related actions:

Model

The Comserv::Model::Log module provides methods for interacting with the log data:

Priority and Status Fields

The log details form has been updated to include the `priority` and `status` fields. These fields are now populated from the controller and displayed as drop-down lists in the form. The `priority` and `status` values are fetched from the database and passed to the template, ensuring that the form displays the correct options for these fields.

Back to top of Documentation

Mail System Documentation

Overview

The Mail system is responsible for managing email communications within the application. It handles the configuration of SMTP settings and the sending of emails to users.

Back to top

Controller

The Comserv::Controller::Mail module handles the routing and logic for mail-related actions:

Back to top

Model

The Comserv::Model::Mail module provides methods for interacting with SMTP configuration data and sending emails:

Back to top

Templates

The following templates are used in the Mail system:

Back to top

Workflow

The typical workflow for managing mail involves displaying the SMTP configuration form, processing the configuration data, and sending emails using the configured settings. The system provides feedback through success and error messages to guide the user through the configuration and email sending process.

Back to top

Back to top of Documentation

Projects System Documentation

Controller

The Comserv::Controller::Project module handles the routing and logic for project-related actions:

Model

The Comserv::Model::Project module provides methods for interacting with the project data:

Templates

The following templates are used in the Projects system:

Workflow

The typical workflow for managing projects involves navigating to the project list, selecting a project to view or edit, and using forms to add or update project information. The system ensures data integrity and user feedback through success and error messages.

Back to top

Back to top of Documentation

Comserv App Documentation: Root.pm

The Root controller in the Comserv application is responsible for handling the initial request and setting up the necessary variables for the application. It does this through several methods:

back to top

index Action

The `index` action is the entry point for the application. It's mapped to the root URL ("/") and is typically the first action executed when a user visits the application. It retrieves the `SiteName` and `ControllerName` from the user's session, determines whether to treat the `ControllerName` as a template or a controller, and then forwards to the appropriate view or controller based on this determination.

back to top

auto Action

The `auto` action is a unique feature of the Catalyst framework that is automatically invoked before any other actions in the request-response cycle. Its primary role in the `Comserv::Controller::Root` package is to prepare the request by identifying the site name from the domain, initializing various session and stash variables, and retrieving necessary data from the database. This setup process enables dynamic content generation and routing based on the specifics of the request and session data.

Functionality

The `auto` action performs the following steps:

  1. Domain Extraction: It extracts the domain from the incoming request and removes any port number, if present.
  2. Site Identification: Using the extracted domain, it identifies the site by querying the `Site` model. This step is crucial for multi-tenant applications where the content and routing may vary based on the site.
  3. Session and Stash Setup: Depending on the site identified, it sets up various session and stash variables. These variables can be used later in the request-response cycle to customize the response.
  4. Data Fetching: It fetches necessary data from the database that might be required for processing the request. This could include site-specific configurations, user data, etc.

Implications

The `auto` action plays a crucial role in the request-response cycle. It sets the stage for all subsequent actions by setting up necessary variables and fetching required data. Any issues in this action can potentially impact the entire request processing, so it's important to handle errors and edge cases properly in this action.

Suggestions for Improvement

While the `auto` action is already doing a great job, there are a few areas where it can be improved:

  1. Error Handling: Robust error handling can be added to handle scenarios where the database is down or the `Site` model returns an error.
  2. Logging: Adding more detailed logging can help in debugging issues. For instance, logging the extracted domain, identified site, and fetched data can provide valuable insights during debugging.
  3. Code Comments: While the code is quite readable, adding comments explaining the purpose of each step can make it easier for new developers to understand the code.
back to top

fetch_and_set Method

The `fetch_and_set` method is a helper method in the `Comserv::Controller::Root` package. It is used to fetch a parameter from the URL, session, or database and set it in the session and stash. This allows for dynamic content and routing based on the parameter value. This method is used in the `auto` action to fetch and set the site name.

Functionality

The `fetch_and_set` method performs the following steps:

  1. Fetch the parameter from the URL query string: The method takes a Catalyst context object (`$c`) and a parameter name (`$param`) as arguments. It uses the `query_parameters` method of the request object to fetch the value of the parameter from the URL query string.
  2. Check if the parameter value is defined: If the parameter value is defined in the URL, it updates the session and stash with this value. If the parameter value is not defined in the URL but is defined in the session, it uses the session value.
  3. Fetch the site name from the Site model: If the parameter value is not defined in the URL or session, it uses the domain name to fetch the site name from the Site model. It removes the port number from the domain, fetches the `site_id` from the `sitedomain` table using the `get_site_domain` method of the Site model, and then fetches the site details from the `sites` table using the `get_site_details` method of the Site model.
  4. Store the site name in the session and stash: If the site is found in the Site model, it stores the site name in the session and stash. It also fetches the `home_view` from the Site table and stores it in the session.
  5. Handle the case when the site is not found: If the site is not found in the Site model, it sets a default value in the session and stash.

Implications

The `fetch_and_set` method is crucial for fetching and setting parameters in the application. It allows for dynamic content and routing based on the parameter value. This method is used in the `auto` action to fetch and set the site name.

back to top

Returning the Controller for a Given Site

The controller for a given site is determined in the `forward_to_controller_based_on_domain` method. This method fetches the site domain record from the Site model using the domain name extracted from the request, retrieves the site details using the `site_id` from the site domain record, and then forwards the request to the appropriate controller based on the controller name retrieved from the site details.

back to top

site_setup Method

The `site_setup` method is a helper method used to fetch site details from the Site model and set up various stash variables based on the site name. These variables are used in the views to customize the appearance and behavior of the application based on the site. This method is used in the `auto` action after the site name has been fetched and set.

back to top

debug

The `debug` method is used to forward the request to the 'TT' view with the 'debug.tt' template. This is used for debugging purposes.

back to top

default

The `default` method is used to handle the default request when a page is not found. It sets the response body to 'Page not found' and the response status to 404.

back to top

documentation

The `documentation` method is used to set the template to 'Documentation/Documentation.tt'. This is used to display the documentation page.

back to top

end

The `end` method is called at the end of every request to render the view. This is the final step in the request lifecycle, where the response is prepared and sent back to the client.

These methods work together to handle the initial request, set up the necessary variables, and render the appropriate view based on the request. This allows for dynamic content and routing based on session data and request parameters.

Back to top of Documentation

Session Plan

Common Reminders

Example Prompt

When reminding the assistant, you can say: "Please follow the guidelines outlined in guidelines.tt, especially regarding the `+-` patch format for code returns and the prohibition on using placeholders in code returns."

Current Session Plan

This section tracks items from the last session and new items created in the current session:

Completed Items

This section tracks items that have been completed:

Back to top of Session Plan

Back to top of Documentation

Database Schema Installation

Back to top

Before you begin, make sure you have the following:

Back to top

Database Schema Management Guide

1. Overview

Brief introduction to the purpose of the schema and its importance in the application.

2. Current Schema Structure

Detailed description of the existing tables and their relationships in both the Ency and Forager databases.

3. Schema Evolution Plan

Step-by-step guide on how to update the schema to accommodate changes in the application requirements:

  1. Identify required schema changes based on application updates.
  2. Create SQL migration scripts to implement schema changes.
  3. Test migration scripts in a development environment.
  4. Execute migration scripts in production, ensuring proper backups are in place.
  5. Verify schema changes and test application functionality.

4. Database Synchronization

Strategies and tools for keeping schema and data synchronized across multiple servers:

  1. Implement automated database synchronization tools.
  2. Establish replication or clustering for high availability and data redundancy.
  3. Regularly monitor synchronization status and resolve any discrepancies.

5. Best Practices

Recommendations for maintaining a well-organized and efficient database schema:

  1. Follow naming conventions for tables, columns, and relationships.
  2. Document schema changes and rationale for future reference.
  3. Regularly optimize database performance and indexes.

6. Schema Versioning

Implementation of version control for the schema to track changes and ensure consistency:

  1. Use version control systems (e.g., Git) to track schema changes.
  2. Tag schema versions for easy reference and rollback if needed.

7. Schema Documentation Updates

Procedures for keeping the schema documentation up-to-date with any changes made to the database structure:

  1. Automate documentation generation from schema metadata.
  2. Include schema change logs in documentation updates.

8. Troubleshooting and Common Issues

Solutions for common problems encountered during schema management and synchronization:

  1. Identify and resolve database conflicts during schema synchronization.
  2. Address performance issues resulting from schema changes.

9. References

Additional resources and tools for further reading on database schema management.

Follow these steps to install the MySQL backup on your server:

  1. Open the command line on your server.
  2. Navigate to the directory where the `ency.sql` file is located.
  3. Log in to the MySQL server with the following command: `mysql -u username -p`. Replace `username` with your MySQL username. You will be prompted to enter your password.
  4. Create a new database with the following command: `CREATE DATABASE new_database;`. Replace `new_database` with the name of your new database.
  5. Select the new database with the following command: `USE new_database;`.
  6. Import the `ency.sql` file with the following command: `source ency.sql;`.

Your MySQL database should now be installed on your server.

Back to top of Documentation

User Management Documentation

User Controller

The User Controller handles all user-related actions and functionalities:

Controller Methods

User Model

The User Model represents the user data and business logic:

Templates

TODO List

Back to top

Back to top of Documentation

Sites

This document provides a detailed explanation of how we manage hosting multiple sites on our server. We will be hosting sites for our clients as well as for our own use. The following steps outline the process of mapping domain names to site configurations and setting up site-specific routes.

Overview of the Process

p> **Overview of the Process:** 1. **Retrieve Domain Name:** Extract the domain name from the request and store it in the session as `HostName`. The domain name is typically in the format `http://shanta.local:3000/`. 2. **Set Site Name:** Use the `HostName` to determine the `SiteName`. 3. **Domain-Site Mapping:** The mapping between `HostName` and `SiteName` is stored in the `sitedomain` table. The `DomainName` field stores the domain, and the `SiteName` field stores the corresponding site ID. 4. **Site Details Retrieval:** Use the `site_id` from the `sitedomain` table to fetch site setup details from the `sites` table. This includes parameters such as the site controller, CSS view name, site display name, email address, etc. 5. **Site Controller Setup:** The site controller is responsible for setting site-specific routes.

**Detailed Explanation:** The following sections explain the code used to implement the above steps, highlighting the purpose of each part and suggesting improvements.

Route Auto Setup

In the `auto` subroutine of the `Root` controller, the following operations are performed to set up the site-specific configurations.

Back to top of Documentation

Setting Up Starman

Overview

Starman is a high-performance web server for Perl, specifically designed to run PSGI applications. This guide provides detailed instructions for setting up Starman to run a Catalyst application, both manually and on boot.

Installation

  1. Use the command cpanm Starman to install Starman.
  2. Alternatively, you can install and setup Starman using cPanel by following these steps:
    1. Log into your cPanel account.
    2. Navigate to the "Perl Modules" section under the "Software" category.
    3. In the "Perl Modules" section, you can install new Perl modules. In the "Install a Perl Module" box, type `Starman` and click on "Install Now".
    4. After the installation is complete, you will see a confirmation message.

Preparing Your Catalyst Application

  1. Create a PSGI file for your Catalyst application. This file tells the web server how to run your application.
  2. Install the dependencies of your application using the command: cpanm --installdeps .
  3. Pull the latest release version from your GitHub repository using the command: git pull origin master.

Configuring Starman to Run Your Application

  1. Use the command: starman --listen :5000 comserv.psgi to run your application.
  2. If you want Starman to keep running even after logging out, use the command: nohup starman --listen :5000 comserv.psgi &

Setting Up Starman to Run on Boot

  1. Create a systemd service file for Starman. Open a new file in the /etc/systemd/system/ directory. You can name it starman.service.
  2. Add the following content to the file:
            [Unit]
            Description=Starman
            After=network.target
    
            [Service]
            ExecStart=/usr/local/bin/starman --listen :5000 /home/shantam/PycharmProjects/CatalystComserv1/Comserv/comserv.psgi
            WorkingDirectory=/home/shantam/PycharmProjects/CatalystComserv1/Comserv
            User=shantam
            Group=shantam
            Restart=always
    
            [Install]
            WantedBy=multi-user.target
            
  3. After saving the file, reload the systemd manager configuration with: sudo systemctl daemon-reload
  4. Enable the service to start on boot: sudo systemctl enable starman
  5. You can start the service immediately with: sudo systemctl start starman
  6. To check the status of the service, use: sudo systemctl status starman
  7. If you need to restart the service after making changes, use: sudo systemctl restart starman

Running Starman as a User

  1. To run Starman in the background, use the command:
    nohup starman --listen :5000 comserv.psgi &
    The nohup command allows the process to continue running after you log out, and the & puts the process in the background.
  2. To stop Starman when it is running in the background, use the ps command to find its process ID (PID):
    ps aux | grep starman
    Find the PID of the Starman process in the output, then use the kill command to stop it:
    kill [PID]
    Replace [PID] with the actual process ID of the Starman process.

Back to top of Documentation

Todo System

The Todo System uses two different date management systems:

Calendar Functionality

The Calendar functionality provides a visual representation of the tasks in the Todo System. It includes three views: day, week, and month. Each view displays the tasks scheduled for the respective time period.

Day View

The day view shows all tasks scheduled for a specific day. Each task is represented as an event on the calendar. The start and end times of the task correspond to the start and end times of the event on the calendar.

Week and Month Views

The week and month views show an overview of the tasks scheduled for the respective time period. Each day in these views contains a summary of the tasks scheduled for that day.

Adapting the Day View

The day view is adapted to work in the week and month views by summarizing the tasks for each day. Instead of showing each task as an individual event, the day view in the week and month views shows a summary of the tasks for that day. This summary includes the number of tasks and the total time scheduled for those tasks.

Adding a Log: Step-by-Step

  1. Click button. It will pass the todo record id and sitename to the log_form.
  2. log_form will use the record id to find the table and fill in the following:
  3. The todo record id will go into todo_record id.
  4. sitename will go into sitename.
  5. subject will go into abstract.
  6. description will go into details.
  7. start_date will go into start_date.
  8. due_date will go into due_date.
  9. start_time puts the time the form is open into the start time field.
  10. end_time is selected by user.
  11. admin is filled in from session role of the user.
  12. priority is pulled from the todo record.
  13. status is selected in with value todo record the word open.

Controller

The Comserv::Controller::Todo module handles the routing and logic for todo-related actions:

Model

The Comserv::Model::Todo module provides methods for interacting with the todo data:

Back to top of Documentation

Workshop Application Creation Process

The workshop application is a Catalyst web-based application that allows users to create, schedule, and manage workshops. The application will include features for adding new workshops, editing existing workshops, and deleting workshops. It will also include features for scheduling workshops at specific times and locations, and for managing the participants who have signed up for each workshop.

To create the Workshop application, we are following a structured approach that involves several steps:

dbix for the database share => { data_type => 'enum', default_value => 'private', extra => { list => ['public', 'private', 'new_value'] // Add the new value here }, }, to alter the table ALTER TABLE `workshop` MODIFY COLUMN `share` ENUM('public', 'private', 'new_value') DEFAULT 'private'; in the details to fetch the record # Assume you have fetched the record data from the database my $record = ...; $c->stash(record => $record); $c->forward('View::TT'); } % USE form %] # to put in the form.
  1. Workshop Controller

    Workshop Controller is a Perl module that handles user interactions with the application. It uses the models to interact with the database and the views to generate the user interface. The controller is responsible for processing user input, invoking the appropriate models to perform the required actions, and rendering the views to display the results.

  2. Workshop Model.

    Workshop Model is a Perl module that represents the core entity in our application. The model is responsible for querying the database to retrieve, insert, update, and delete workshops, as well as for performing any business logic related to workshops.

    We connect to the datbase with # Get a DBIx::Class::Schema object my $schema = $c->model('DBEncy'); # Get a DBIx::Class::ResultSet object my $rs = $schema->resultset('User'); # Find the user in the database my $user = $rs->find({ username => $username });

  3. Workshop Result

    1. id: this field is auto incremented.
    2. sitename: this field is the sitename of the owner of the site
    3. title: this field is the name of the workshop
    4. description: this field is the description of the workshop
    5. date: this field is the date of the workshop
    6. location: the location of the workshop
    7. instructor: this field is the instructor(s)
    8. max_participants: this field is the maximum number of participants for the workshop
    9. share: this field is the share status of the workshop
    10. end_time: this field is the end_time of the workshop
    11. time: this field is the time of the workshop
  1. Define the Data Models: We have defined several data models to represent the core entities in our application. These include WorkShop, Participant, and SiteWorkshop. Each model corresponds to a table in the database and defines the fields (columns) in that table.
  2. Establish Relationships Between Models: We have established relationships between our models to reflect the associations between our entities. For example, we have a belongs_to relationship from WorkShop to Site, indicating that each workshop belongs to a site.
  3. Create the Views: We have created a Template Toolkit file workshops.tt that defines the user interface for displaying and interacting with workshops. This file includes HTML and Template Toolkit directives to display a list of workshops and provide links for adding, editing, and deleting workshops.

Next steps:

  1. Implement the Controllers: We will implement controllers that handle user interactions with our application. These controllers will use the models to interact with the database and the views to generate the user interface.
  2. Implement the Service Layer: We will implement a service layer that encapsulates the business logic of our application. This will include functions for checking if a user is allowed to create a workshop, if a workshop is full, or if a workshop can be scheduled at a certain time.
  3. Test the Application: We will thoroughly test our application to ensure that it works as expected. This will include unit tests for our models, controllers, and service layer, as well as integration tests for the application as a whole.
  4. Deploy the Application: Once we are confident that our application is working correctly, we will deploy it to a production environment.

Remember, this is a high-level overview and the actual implementation might involve additional steps depending on the specific requirements of your application.

Back to top of Documentation

The 'Ve7tit' Documentation

This is my documentation for the 've7tit' application. All the information you need to know about the application is here.

All routes are dealt with in the ve7tit controller.

Routes

Back to top of Documentation

Inventory Management

Table of Contents

The Inventory module provides tools for managing items, their attributes, suppliers, and sub-items within the Comserv application.

Inventory Overview

Inventory Management in Comserv involves tracking and managing all physical assets and their components:

Item Management

Item Management features include:

Supplier Management

Supplier Management involves:

Sub-Items

Sub-items management allows for:

For more detailed instructions on how to use these features, please refer to the specific documentation for each aspect of inventory management as we continue to develop and refine our strategies.

Instructions for Developers

Welcome to the Comserv Application Documentation. Here are some guidelines and best practices to keep in mind while working with this project:

We are committed to evolving the Comserv application to meet the needs of our users. Please contribute by keeping this documentation up to date and following the guidelines provided.

Back to top of Documentation