angularjs expand & collapse issue - javascript

I am new in angularjs and currently i'm facing this issue.
Problem
when i clicked on any of the node, all the nodes will be expanded or collapsed.
For example : (Before clicking on the node)
After clicking on the node
Code
<div class="item">Data Visualization</div>
<div class= "item">
<i class="icon ion-arrow-right-b" ng-model="collapsed" ng-click="collapsed=!collapsed"><strong> AGV Mileage Vs Timestamp</strong></i>
<div ng-show="collapsed">
<div id ="agvmileage">
<div class = "horizon">
<canvas width="960" height="120">
<script src="/static/js/frontend/cubi-agv.js"></script>
</div>
</div>
</div>
</div>
<div class= "item">
<i class="icon ion-arrow-right-b" ng-model="collapsed" ng-click="collapsed=!collapsed"><strong> Board Temperature Vs Timestamp</strong></i>
<div ng-show="collapsed">
<div id ="agvmileage">
<div class = "horizon">
<canvas width="960" height="120">
<script src="/static/js/frontend/cubi-agv.js"></script>
</div>
</div>
</div>
</div>
<div class= "item">
<i class="icon ion-arrow-right-b" ng-model="collapsed" ng-click="collapsed=!collapsed"><strong> Laser Sensor Output Vs Timestamp</strong></i>
<div ng-show="collapsed">
<div id ="agvmileage">
<div class = "horizon">
<canvas width="960" height="120">
<script src="/static/js/frontend/cubi-agv.js"></script>
</div>
</div>
</div>
</div>
<div class= "item">
<i class="icon ion-arrow-right-b" ng-model="collapsed" ng-click="collapsed=!collapsed"><strong> Battery Current Vs Timestamp</strong></i>
<div ng-show="collapsed">
<div id ="agvmileage">
<div class = "horizon">
<canvas width="960" height="120">
<script src="/static/js/frontend/cubi-agv.js"></script>
</div>
</div>
</div>
</div>
And if possible, how can i declare the "data visualization" as parent node and
others as child node then perform expand and collapse.
Please enlighten me on this, thanks in advance.

Each item needs to have its own separate collapsed state. For example:
Item 1
<i ng-model="collapsedMileage" ng-click="collapsedMileage = !collapsedMileage">
<strong>AGV Mileage Vs Timestamp</strong>
</i>
<div ng-show="collapsedMileage">
<!-- the rest of your template -->
</div>
Item 2
<i ng-model="collapsedLaser" ng-click="collapsedLaser = !collapsedLaser">
<strong>Laser Sensor Output Vs Timestamp</strong>
</i>
<div ng-show="collapsedLaser ">
<!-- the rest of your template -->
</div>
Item 3
<i ng-model="collapsedBattery" ng-click="collapsedBattery = !collapsedBattery">
<strong>Battery Current Vs Timestamp</strong>
</i>
<div ng-show="collapsedBattery">
<!-- the rest of your template -->
</div>

Related

How to make my HTML list with many items have less lines?

So I have 22 different lists with 50-100 items inside. And they take ~25k lines of html code. How to make them take less lines?
For example:
I want this to have only one item in list that repeats many times but with different ids, ids in classicImage/shortyImage(' ') and different images if this is possible
<a onclick="showClassic()">
<div class="classic">
<img src="images/classic/classic_default.png" class="imgcol2" id="classicimg" style="max-height: 75px; max-width: 150px;" >
<div class="wname" style="width: 150px;">CLASSIC</div>
</div>
</a>
<a onclick="showShorty()">
<div class="shorty">
<img src="images/shorty/shorty_default.png" class="imgcol2" id="shortyimg">
<div class="wname" style="width: 150px;">SHORTY</div>
</div>
</a>
<div class="results">
<ul id="classicList">
<li class="collection-item">
<!-- sets source of image with id="classicimg" to source of image with id classic-avalanche -->
<a onclick="classicImage('classic-avalanche'); setClassicPrice(1275)">
<div class="result-container">
<div class="result">
<img src="images/classic/classic_avalanche.png" class="windowimage" id="classic-avalanche">
</div>
<p class="skinname">Classic Avalanche</p>
</div>
</a>
</li>
<li class="collection-item">
<!-- sets source of image with id="classicimg" to source of image with id classic-default -->
<a onclick="classicImage('classic-default'); setClassicPrice(0)">
<div class="result-container">
<div class="result">
<img src="images/classic/classic_default.png" class="windowimage" id="classic-default">
</div>
<p class="skinname">Classic Default</p>
</div>
</a>
</li>
</ul>
</div>
<div class="results">
<ul id="shortyList">
<li class="collection-item">
<!-- sets source of image with id="shortyimg" to source of image with id shorty-aerosol -->
<a onclick="shortyImage('shorty-aerosol'); setShortyPrice(0)">
<div class="result-container">
<div class="result">
<img src="images/shorty/shorty_aerosol.png" class="windowimage" id="shorty-aerosol">
</div>
<p class="skinname">Shorty Aerosol</p>
</div>
</a>
</li>
<li class="collection-item">
<!-- sets source of image with id="shortyimg" to source of image with id shorty-default -->
<a onclick="shortyImage('shorty-default'); setShortyPrice(0)">
<div class="result-container">
<div class="result">
<img src="images/shorty/shorty_default.png" class="windowimage" id="shorty-default">
</div>
<p class="skinname">Shorty Default</p>
</div>
</a>
</li>
</ul>
</div>
Considering you tagged javascript and html only, i assume you have no backend code to handle the templating.
So my best advice would be to divide those multiple lists into multiple .html file and load them with JS, like this example with jQuery :
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#firstList").load("firstList.html");
});
</script>
</head>
<body>
<div id="firstList"></div>
</body>
</html>

innerHTML property not working with owl carousel

I am fetching data from firestore database to create a product card so that I can display the product cards inside a carousel. Owl carousel to be specific. I am using the innerHTML property in javascript to add the product cards programmatically. The Owl carousel seems to not work when I do so but when I create the cards statically in html the carousel works. What could be the problem?
Code:
Html:
<div class="product-area most-popular section">
<div class="container">
<div class="row">
<div class="col-12">
<div class="section-title">
<h2>Hot Items</h2>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="owl-carousel popular-slider" id="owlCarousel">
<!--product cards go here-->
</div>
</div>
</div>
</div>
</div>
Javascript:
var view2 = document.getElementById("owlCarousel");
db.collection("products").where("hot" , "==" , true)
.get().then((querySnapshot)=> {
querySnapshot.forEach((doc) => {
var image = doc.data().images[0];
var image2 = doc.data().images[1];
var title = doc.data().title;
var price = doc.data().pricing.toString();
var hot = doc.data().hot;
var discount = doc.data().discount;
var price = doc.data().pricing;
//product card creation
view2.innerHTML += `
<div class="single-product">
<div class="product-img">
<a href="product-details.html">
<img class="default-img" src="${image}" alt="#">
<img class="hover-img" src="${image2}" alt="#">
<span class="out-of-stock">Hot</span>
</a>
<div class="button-head">
<div class="product-action">
<a data-toggle="modal" data-target="#exampleModal" title="Quick View" href="#"><i class=" ti-eye"></i><span>Quick Shop</span></a>
<a title="Wishlist" href="#"><i class=" ti-heart "></i><span>Add to Wishlist</span></a>
<a title="Compare" href="#"><i class="ti-bar-chart-alt"></i><span>Add to Compare</span></a>
</div>
<div class="product-action-2">
<a title="Add to cart" href="#">Add to cart</a>
</div>
</div>
</div>
<div class="product-content">
<h3>${title}</h3>
<div class="product-price">
<span>Ksh. ${price}</span>
</div>
</div>
</div>
`
});
});
I just had the same problem.
What you should do is initialize the OWL CAROUSEL after you add the template (inner html);
for example:
view.innerHtml = `<div> content </div`;
$('.owl-carousel').owlCarousel({
//here you can add the props or events
})
This worked for me! hope this could hel you :)

Populating HTML Table Data without Repetition

How can I populate multiple tables without copy and pasting code.
For instance loop through an array and assign
<p>AMD</p>
without copy and pasting the code below. Maybe looping and incrementing an id written in javascript. I just dont know how to go about it.
<div class="chat-history">
<div class="chat-message clearfix">
<img src="http://lorempixum.com/32/32/people" alt="" width="32" height="32">
<div class="chat-message-content clearfix" onclick=alert("test")>
<span class="chat-time"></span>
<h5></h5>
<p>AMD</p>
</div> <!-- end chat-message-content -->
I tried this im still working on it not fully understanding yet.
<div class="chat">
<div class="chat-history">
<div class="chat-message clearfix">
<img src="http://lorempixum.com/32/32/people" alt="" width="32" height="32">
<div id="company" class="chat-message-content clearfix" onclick=alert("hush")>
<span class="chat-time"></span>
<h5></h5>
<p >DCTH</p>
</div> <!-- end chat-message-content -->
</div> <!-- end chat-message -->
<script>
for (i = 0; i < 10; i++) {
document.getElementById("company").innerHTML+= "<p>TEST</p>"
}
</script>
your items can go inside a div and then through script you should insert your items in a <p> tag. added a sample script below:
<div class="chat-history">
<div class="chat-message clearfix">
<img src="http://lorempixum.com/32/32/people" alt="" width="32" height="32">
<div class="chat-message-content clearfix" onclick=alert("hush")>
<span class="chat-time"></span>
<h5></h5>
<div id="company"></div>
</div> <!-- end chat-message-content -->
</div> <!-- end chat-message -->
<script>
var company = ["AMD", "APPLE"];
company.forEach(function(i) {
document.getElementById("company").innerHTML+= "<p>" + i + "</p>";
});
</script>

How to edit html file from an another one

I want to select element with sidebar id in downloader.html from an another html document (settings.html).
downloader.html
<body>
<div class="ui visible left vertical thin sidebar menu" id='sidebar'>
<div class='item'>
<img class='ui medium image' src='./../../resources/images/logo_256x256.png'>
</div>
<a class="item" id='dashboard_btn'>
<i class="desktop icon"></i>
Dashboard
</a>
<a class="item" id='statistics_btn'>
<i class="area chart icon"></i>
Statistics
</a>
<a class="item" id='settings_btn'>
<i class="settings icon"></i>
Settings
</a>
</div>
<div class='dimmed pusher'>
<button class="ui icon button" id='sidebar_btn'>
<i class="angle double left icon" id='sidebar_btn_icon'></i>
</button>
<div id='content'>
<!-- All content goes here. -->
</div>
</div>
<script>
$(document).ready(function () {
$('#sidebar_btn').on('click', function () {
$('#sidebar').sidebar('toggle');
$('#sidebar_btn_icon').toggleClass('right');
});
$("#dashboard_btn").on("click", function () {
$("#content").load("./items/dashboard/dashboard.html");
});
$("#statistics_btn").on("click", function () {
$("#content").load("./items/statistics/statistics.html");
});
$("#settings_btn").on("click", function () {
$("#content").load("./items/settings/settings.html");
});
});
</script>
settings.html
<body>
<div class='center'>
<h2 class="ui icon header">
<i class="settings icon"></i>
<div class="content">
Settings
<div class="sub header">Sample text.</div>
</div>
</h2>
<div class='center child'>
<div class="ui toggle checkbox">
<input name="public" type="checkbox">
<label>Dark theme.</label>
</div>
</div>
</div>
<script>
//Select 'sidebar' element from downloader.html using jquery
</script>
Please, do not pay attention to mixed ' with " in html code. It is my fault and it will be fixed before app release.
You can use .load() with hash set within "settings.html"
$("#element").load("downloader.html #sidebar")

Transform tables when screen size changes

I have 3 columns of data, each with 2 rows inside. I would like to make to transform 3x2 table into 1x6 table, when the width of the screen is less than some value. Any idea how to achieve this?
My column has the following structure:
<div class="one-third animate_afl">
<div class="w-iconbox custom_img iconpos_left size_big type_default color_primary">
<div class="w-iconbox-link" >
<div class="w-iconbox-icon">
<i class="fa fa-"></i>
<img src="wp-content/uploads/2015/04/9-over.png" alt="">
</div>
<h4 class="w-iconbox-title">Title</h4>
</div>
<div class="w-iconbox-text">
<p>Paragraph text.</p>
</div>
</div>
<div class="g-hr type_invisible">
<span class="g-hr-h">
<i class="fa fa-star"></i>
</span>
</div>
<div class="w-iconbox custom_img iconpos_left size_big type_default color_primary">
<div class="w-iconbox-link">
<div class="w-iconbox-icon">
<i class="fa fa-"></i>
<img src="wp-content/uploads/2015/04/modul1-over.png" alt="">
</div>
<h4 class="w-iconbox-title">Title 2</h4>
</div>
<div class="w-iconbox-text">
<p>Paragraph text 2.</p>
</div>
</div>
<div class="w-iconbox custom_img iconpos_left size_big type_default color_primary">
<div class="w-iconbox-text"></div>
</div>
</div>
This would surely involve CSS media queries, which allow you to do this very thing. You can even set multiple break-widths where your css can change for each width you want, as many as you want.

Categories