Skip to content
Snippets Groups Projects
Select Git revision
  • fa4caa91665b40ec6116daa99edb678337dc26e2
  • main default protected
  • Tormod
  • Alex
  • Martin
  • mqttTest
6 results

addData.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    scaffolding.js 6.01 KiB
    import React from "react";
    import "../Assets/Styles/scaffolding.css"
    import CardElement from "../components/scaffolding/scaffoldingCard";
    import {PROJECTS_WITH_SCAFFOLDING_URL, SCAFFOLDING_URL, STORAGE_URL} from "../Constants/apiURL";
    import {GetCachingData} from "../Middleware/addData";
    import {SpinnerDefault} from "../components/Indicators/Spinner";
    import {InternalServerError} from "../components/Indicators/error";
    
    /**
     Class that will create an overview of the scaffolding parts
     */
    class ScaffoldingClass extends React.Component {
        constructor(props) {
            super(props);
            this.state={
                isLoaded1: false,
                isLoaded2: false,
                scaffolding: props.scaffolding,
                storage:props.storage,
                items: [],
                selectedOption: ""
            }
        }
    
    
        /**
         * Function that will count numbers of occurrences different types of scaffolding.
         *
         * Code acquired from https://www.geeksforgeeks.org/how-to-count-number-of-occurrences-of-repeated-names-in-an-array-of-objects-in-javascript/
         *
         * @param arr is the array we are iterating.
         * @param key is the field we want to count.
         * @returns {*[]}
         */
        countObjects(arr, key){
            let arr2 = [];
            arr?.forEach((x)=>{
                // Checking if there is any object in arr2
                // which contains the key value
                if(arr2?.some((val)=>{return val[key] === x[key]})){
                    // If yes! then increase the occurrence by 1
                    arr2?.forEach((k)=>{
                        if(k[key] !== x[key]){
                            k["occurrence"]++
                        }
                    })
                }else{
                    // If not! Then create a new object initialize
                    // it with the present iteration key's value and
                    // set the occurrence to 1
                    let a = {}
                    a[key] = x[key]
                    a["occurrence"] = 1
                    arr2?.push(a);
                }
            })
    
            return arr2
        }
    
    
        /**
         * Function to add occurrences of type scaffolding in desired body.
         *
         * @param scaffold count of occurrences
         * @param storage objects in an array.
         * @returns {{scaffolding: *[]}}
         */
        scaffoldingAndStorage(scaffold, storage){
            const scaffoldVar = {