Total.js Platform
Total.js Platform

Total.js Platform news and tutorials

Building SaaS Website #14: Single Page Applications (SPA) - Admin Panel (Part 2)

Building SaaS Website #14: Single Page Applications (SPA) - Admin Panel (Part 2)

Introduction

In the previous blog of this series, we introduced the foundational setup for the TotalGPT SaaS admin panel. This time, we focus on creating the views and understanding how Single Page Applications (SPA) leverage the power of the Total.js server and the JComponent library.

This part of the series lays the groundwork for structuring the admin panel’s HTML and integrates JComponent to handle dynamic UI elements and routing seamlessly.


Definitions

Total.js Framework

Total.js is the core of the Total.js Platform, a robust ecosystem designed for building fast and real-time applications. It includes tools, libraries, and ready-to-use apps, all integrated into a seamless development environment. This project uses the latest version of Total.js Framework as of January 2025.

JComponent (Total.js UI)

JComponent is a client-side library within the Total.js ecosystem, built to create interactive user interfaces similar to Angular or React. It features:

  • A core for SPA creation and reusable components.
  • Client-side routing for HTML history management.
  • Tangular template engine.
  • Helpers for arrays, numbers, strings, dates, and more.
  • Compatibility with jQuery.

With these tools, developers can also create hybrid mobile applications (PWA).

Integration is straightforward:

Note: This blog focuses on setting up the admin panel and doesn’t cover the full library. A separate series will delve into Total.js UI.


JComponent Integration

We will set up admin.html in the views folder. Unlike the website, this admin panel won’t split views into layout_admin.html and admin.html, so you can see everything in one place.

Setting Up admin.html

Create /views/admin.html and add the following:

Header and Components Setup

Add the header with a breadcrumb UI component:

Side Navigation Menu

Define the side navigation menu using navlayout:

JSON Model for Plugins

Add the JSON model to load plugins dynamically:

Adding the client side common logic:

Certainly! Part 3 of your SPA admin panel blog post focuses on Plugins and their functionality in the Total.js framework. Below is the detailed blog post in Markdown format, incorporating code snippets, explanations, and comments.



Client side Plugins

In this section, we dive into the client side Plugins feature of JComponent, which provides a modular and flexible way to handle dynamic content like pages, forms, windows, or other components in a SPA (Single Page Application). We'll explore the implementation, usage, and best practices


What Are client side Plugins in JComponent?

Plugins are self-contained modules that:

  • Handle dynamic parts of your application.
  • Can be easily added or removed without affecting the rest of your application.
  • Manage their own events and watchers, which are automatically cleaned up when the plugin is removed.

In Total.js, plugins allow you to dynamically build and manage content in your admin panel while keeping the codebase modular and maintainable.


Plugin Implementation: Common Script Example

Below is the core script for defining and managing plugins in your Total.js SPA. The code also includes comments explaining each part.

Environment Variables and Definitions

Define useful environment variables and configure fallback behaviors.



Plugin Management

Defining a Plugin

Plugins are defined using the PLUGIN method. Here’s an example:



Middleware and Routing

Middleware is used to manage route initialization and redirections.



Event Listeners and Flags

Use event listeners to manage UI states like loading animations.



Code Initialization

Load required data during app initialization.

Summary

In this part, we implemented a modular plugin system that allows for:

  1. Easy management of dynamic content.
  2. Client-side routing for individual plugins.
  3. Seamless integration with OpenPlatform.
  4. Efficient handling of UI states and data fetching.