Analyzing and displaying contents within bootstrap panels

Currently, I am involved in a project that entails extracting data from an API related to a school's timetable. The code snippet below outlines the process I have implemented to gather all essential information:


var timetable = [];
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

// Iterate through the data and extract specific details
for (var i = 0; i < json.reservations.length; i++) {
    if (json.reservations[i].resources != null) {
        for (var j = 0; j < json.reservations[i].resources.length; j++) {
            var reservation = json.reservations[i];
            var resource = json.reservations[i].resources[j];

            // Extract student group information
            if (resource.type === "student_group") {
                if (timetable.indexOf("name")) {
                    var studentGroup = timetable.push(resource.name.bold() + "<br/>");
                }
            }

            // Extract scheduling group information
            if (resource.type === "scheduling_group") {
                if (timetable.indexOf("name")) {
                    var schedulingGroup = timetable.push(resource.name + "<br/>")
                }
            }

            // Extract room details
            if (resource.type === "room") {
                if (timetable.indexOf("code")) {
                    var room = timetable.push(resource.code.bold() + "<br/>" + "<br/>");
                }                                     
            }
        }                              
    }

    // Extract subject information
    if (reservation != null) {
        if (timetable.indexOf("subject")) {
            var subject = timetable.push("<br/>" + reservation.subject.bold() + "<br/>");
        }
    }

    // Retrieve day name (Mon, Tue, Wed...)
    var day = new Date(reservation.startDate);                          
    var date = timetable.push(days[day.getDay()].bold() + "<br/>");

    // Obtain starting timestamp
    if (reservation != null) { 
        var start = reservation.startDate;
        var startStr = start.split("-").join('/').slice(0, 10) + "<br/>" + start.slice(11, 16);
        lukkari.push(startStr + " - ");
    }

    // Determine ending timestamp
    if (reservation != null) {
        var end = reservation.endDate;
        var endStr = end.slice(11, 16);
        timetable.push(endStr + "<br/> <br/>");
    }

    var line = timetable.push("_______________________________<br/>");

    // Output the results
    document.getElementById("demo").innerHTML = timetable.join("");

The output displayed includes various details such as room codes, timings, and subjects allocated on certain days of the week.

However, instead of merely storing this data within an array, I aim to organize it into separate columns based on each day of the week (Monday, Tuesday, etc.). One potential approach would involve utilizing collapsible Bootstrap panels, where each panel corresponds to a specific day (e.g., Monday, Tuesday).

Could you suggest an efficient method to associate the extracted day names from the collected data (as seen in the timetable array) with the respective panels displaying those particular days?

If not, are there any alternative strategies or creative solutions that could be considered for this task?

Answer №1

When it comes to handling dynamic content, I highly recommend utilizing a templating engine such as Handlebars.js

I recently wrapped up a project that heavily relied on Handlebars in conjunction with Bootstrap 3, and I found the integration process to be seamless and efficient

While delving into the intricacies of Handlebars is beyond the scope of this discussion, it essentially allows you to create an HTML template with {{tokens}} placeholders for your data. One particularly valuable feature is the ability to iterate through a dataset to generate multiple panels for displaying all relevant information

The syntax within your markup will resemble something like:

{{#each event}}
  <div class="panel">
    <h3>{{event.dayOfWeek}}</h3>
    <p>
      <label>{{event.date}}</label>
      <label>{{event.startTime}} - {{event.endTime}}</label>
    </p>
  </div>
{{/each}}

Handlebars proves to be incredibly user-friendly and versatile. Do yourself a favor and explore its capabilities. It's truly a game-changer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Validating email addresses using regular expressions in JavaScript

After implementing a regex test for the email input, I noticed that an alert is triggered when an incorrect email format is submitted. However, even after dismissing the alert, the email still gets posted to the address specified in the page send_msg.php, ...

Mastering the art of extracting JSON key-value pairs using JavaScript

I am looking to extract the key from a JSON file and then populate another select input with the corresponding values using JavaScript. Below is the structure of my JSON file: "city": { "Afghanistan": [ "Herat", "Kabul", "Kandahar", "Molah", "R ...

Java - Converting JSON format

As a beginner in Java, I am exploring ways to transform Json data just like in the following example. I'm unsure whether to use json array, mapper or List for this task Here's the scenario: Input Document: { "data1": "A", ...

Retrieving data from a child component that has been added in React

One of the challenges I am facing is dealing with a main react component that dynamically appends child components, like <Child />, on button click The structure of my Child component looks something like this: <form> <input .... /> ...

Is there a way to append items to the main level of an array?

I am attempting to populate an array with objects in order to achieve the following structure: myobject1: Object: ItemInside: Object myobject2: Object ItemInside: Object myobject3: Object ItemInside: Object myobject4: Object ItemInside: Ob ...

What is the proper method for utilizing the "oneOf" keyword in this schema?

Is it possible to have either option A or B, but not both (mutually exclusive)? In Draft 3, I am required to use whatever is available, even though the version on top says 4. This is because when using an array for "required", it throws an error stating t ...

Determine the quantity of characters available in a contenteditable field

I have implemented a directive that allows me to input editable content inside a tag Recently, I made modifications to include a character counter feature. However, I noticed that when I add line breaks, the character count increases erroneously. https: ...

Issue with unresolved module in ESLint

Currently, I am utilizing the vss-web-extension-sdk in my project. To ensure the validity of my files, I have integrated ESLint along with eslint-plugin-import and eslint-import-resolver-typescript. import { WidgetSettings, WidgetStatus } from "TFS/Dashbo ...

The media print is not displaying correctly when attempting to print with JavaScript

I am attempting to print a div using the following javascript code: var divToPrint = document.getElementById(curid); var newTab = window.open('', 'Print-Window'); newTab.document.open(); newTab.document.write('<h ...

The footer should remain at the bottom of the page without being permanently fixed

Is there a way to keep the bootstrap footer at the bottom without fixing it in place? In the code example below, the footer should always appear at the bottom. The white space after the footer should come before it. Using sticky-bottom achieves this, but ...

Using Node.js for a game loop provides a more accurate alternative to setInterval

In my current setup, I have a multiplayer game that utilizes sockets for asynchronous data transfer. The game features a game loop that should tick every 500ms to handle player updates such as position and appearance. var self = this; this.gameLoop = se ...

Tips for excluding a CSS property from a class override

I have a file called _buttons.scss: .btn { display: inline-block; font-family: $btn-font-family; font-weight: $btn-font-weight; color: $body-color; text-align: center; text-decoration: if($link-decoration == none, null, none); white-space: $b ...

What is the mechanism of concurrency in a Node.js and Express application?

(Success! Issue Resolved) To illustrate my question, I will begin with a code example: var express = require('express'); var customModule = require('./custom-module'); var app = express(); // Page A app.get('/a', function( ...

Tips for splitting the json_encode output in Javascript

Looking for help with extracting specific values from JSON data retrieved via PHP and AJAX. I only want to display the agent name in my ID, not the entire object that includes "name" : "Testing". Here is the console output: [{"agent_module_id":"1","agen ...

Encountering Axios 404 error while trying to access the routes directory

My server.js file in Express and Node.js contains the bulk of my back-end code, except for my database config file. The file is quite lengthy, and I want to enhance maintainability by breaking it down into smaller modules that can be imported. To start t ...

What is the most effective way to implement a global notifications feature?

I'm working on developing my mobile API using Node.js and I am unsure about the best approach to store my notifications functions. These functions are being called multiple times in my code and I am undecided whether to use a global function, class, o ...

The dynamic loading of select tag options in Vue.js is not rendering properly

I'm having trouble displaying a select tag with options loaded from a Vue object. However, when I try to render it, something seems off: https://i.sstatic.net/odbC6.png Here is the HTML markup for the select tag: <div class="form-group ui-model" ...

The conditional statement in EJS is not functioning properly

I have been incorporating the ejs template into my express application. Following the guidance on the official page of the template (https://www.npmjs.com/package/ejs), I am utilizing an if conditional to display a variable only if it has been defined. Her ...

Creating a dual-column dropdown menu that works seamlessly with Angular 4/5

I'm currently working on an Angular project where I need to implement a multi-column dropdown list, similar to the example shown in the image linked below: https://i.sstatic.net/VfmSF.jpg Initially, I tried using a selectMenu widget from jQuery to ac ...

Execute a database query to search for patterns using Regular Expressions within the

As I embark on a new project, I find myself questioning my approach before diving in too deep and realizing it may not be the most efficient path. Within the realm of a large company where we develop unofficial tools for internal use, I am faced with limi ...