Display data to every <td> from Firestore using Nuxt - google-cloud-firestore

how do I want to display those particular values into those particular td tag from a document in Firestore using Nuxt?
I already looking into some of the StackOverflow QnA but have not quite found the answer that I wanted.
Here is the image of the table:
The table
So as you can see I manage to get the document into my app, but I want the data to be on that right column. How I can achieve this?
my HTML part:
<template>
<div id="SubPackageDetailTable">
<h2>Sub-Packages Detail</h2>
<table
items="SubPackagesDetails">
<tr>
<th>Subcontractor</th>
<td>{{ SubPackagesDetails.SubContractorName }}</td>
</tr>
<tr>
<th>WPC</th>
<td>{{ SubPackagesDetails.WorkPackageContractorName }}</td>
</tr>
<tr>
<th>Package</th>
<td>{{ SubPackagesDetails.Package }}</td>
</tr>
<tr>
<th>Sub-Package</th>
<td>{{ SubPackagesDetails.Subwork }}</td>
</tr>
<tr>
<th>Code</th>
<td>{{ SubPackagesDetails.code }}</td>
</tr>
<tr>
<th>Commencement Date</th>
<td>{{ SubPackagesDetails.CommencementDate }}</td>
</tr>
{{ SubPackagesDetails }}
</table>
</div>
</template>
my Script part:
<script>
import firestore from "#/plugins/firebasetest";
export default {
data: () => ({
SubPackagesDetails: [
{
SubContractorName: '',
WorkPackageContractorName: '',
Package: '',
Subwork: '',
code: '',
CommencementDate: '',
}
],
}),
created() {
this.refreshSubPackagesDetails();
},
methods: {
refreshSubPackagesDetails() {
this.SubPackagesDetails = [];
firestore
.collection("subsub")
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
this.SubPackagesDetails.push({ ...doc.data(), id: doc.id });
this.loading = false;
});
console.log(this.SubPackagesDetails);
});
},
},
}
</script>

Thanks to #kissu, using v-for solved the problem. Not sure how to explain how it can work but here is how I do it. I'll put as answer in case if someone had a problem same as me.
<table>
<tr v-for="(subcontractorname, i) in SubPackagesDetails" :key="i">
<th>Subcontractor</th>
<td
>{{ subcontractorname.SubContractorName }}</td>
</tr>
<tr v-for="(workpackagecontractorname, i) in SubPackagesDetails" :key="i">
<th>WPC</th>
<td>{{ workpackagecontractorname.WorkPackageContractorName }}</td>
</tr>
<tr v-for="(packages, i) in SubPackagesDetails" :key="i">
<th>Package</th>
<td>{{ packages.Package }}</td>
</tr>
<tr v-for="(subwork, i) in SubPackagesDetails" :key="i">
<th>Sub-Package</th>
<td>{{ subwork.Subwork }}</td>
</tr>
<tr v-for="(Code, i) in SubPackagesDetails" :key="i">
<th>Code</th>
<td>{{ Code.code }}</td>
</tr>
<tr v-for="(commencementdate, i) in SubPackagesDetails" :key="i">
<th>Commencement Date</th>
<td>{{ commencementdate.CommencementDate }}</td>
</tr>
</table>

Related

Not able to retrieve data from MongoDB using Flask [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I have extablised a successful db connection in flask and trying to display courses in courses.html as follows:
#app.route('/courses')
#app.route('/courses/<term>')
def courses(term = None):
if term == None:
term= 2023
classes = Courses.objects.all()
return render_template('courses.html', coursesData=classes, courses=True, term=term)
The courses class is as follows:
class Courses(db.Document):
courseID=db.StringField(max_length=10, unique=True)
title = db.StringField(max_length=100)
description = db.StringField(max_length=300)
credits = db.IntField()
term=db.StringField(max_length=100)
The courses.html page is as follows:
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Course ID</th>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col">Credits</th>
<th scope="col">Term</th>
<th scope="col">Enroll</th>
</tr>
</thead>
<tbody>
{% for data in coursesData %}
<tr>
<td scope='row'>{{ data["courseID"] }}</td>
<td>{{ data["title"] }}</td>
<td>{{ data["description"] }}</td>
<td>{{ data["credits"] }}</td>
<td>{{ data["term"] }}</td>
<td>
<form action="{{ url_for('enrollment') }} " , method="POST">
<input type="hidden" name="id" value="{{ data[ 'courseID' ] }}">
<input type="hidden" name="title" value="{{ data[ 'title' ] }}">
<input type="hidden" name="term" value="{{ data[ 'term' ] }}">
<button>Enroll</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
When i run it, no courses were displayed. Can anyone please help me with this?
Instead of:
classes = Courses.objects.all()
Could you please try:
classes = Courses.query.all()
That is the "legacy query interface", the latest syntax is HERE.

Sort list by order number with record grouping

I have a list of orders. I would like to sort the list in the way that if there are more than one order placed by the same customer, the orders are grouped. It is hard to explain by words so here is an example:
This is the list sorted by Order No:
<table>
<tr>
<th>Customer</th>
<th>Order No</th>
</tr>
<tr>
<td>A</td>
<td>1</td>
</tr>
<tr>
<td>B</td>
<td>2</td>
</tr>
<tr>
<td>C</td>
<td>3</td>
</tr>
<tr>
<td>A</td>
<td>4</td>
</tr>
<tr>
<td>A</td>
<td>5</td>
</tr>
<tr>
<td>D</td>
<td>6</td>
</tr><tr>
<td>C</td>
<td>7</td>
</tr>
</table>
I would like this list to look like this:
<table>
<tr>
<th>Customer</th>
<th>Order No</th>
</tr>
<tr>
<td>A</td>
<td>1</td>
</tr>
<tr>
<td>A</td>
<td>4</td>
</tr>
<tr>
<td>A</td>
<td>5</td>
</tr>
<tr>
<td>B</td>
<td>2</td>
</tr>
<tr>
<td>C</td>
<td>3</td>
</tr>
<tr>
<td>C</td>
<td>7</td>
</tr>
<tr>
<td>D</td>
<td>6</td>
</tr>
</table>
I will be very grateful for any hint :)
Thank you!
You can create a map of customers and orders.
For each map entry create a list of ordernumbers.
Doing so you can sort every order list.
Example:
const list = [
{ customer: 'A', ordernumber: 2 },
{ customer: 'B', ordernumber: 1},
{ customer: 'A', ordernumber: 1 },
{ customer: 'A', ordernumber: 3 }
]
customerOrderMap = {}
list.forEach(element => customerOrderMap[element.customer] = [])
list.forEach(element => customerOrderMap[element.customer].push(element.ordernumber))
Object.keys(customerOrderMap).forEach(key => {
console.log(customerOrderMap[key].sort((a, b) => a - b))
})
console.log(customerOrderMap)

Submit button in Symfony view without a reusable form type

In my Controller I have an action:
/**
* #Route("/admin/tour/approve/{id}",name="approve_one_tour")
*/
public function approveOneTourAction($id,Request $request)
{
$tour=$this->getDoctrine()->getRepository('HearWeGoHearWeGoBundle:Tour')->findById($id);
if ($request=='POST')
{
$tour->setStatus(true);
$em=$this->getDoctrine()->getEntityManager();
$em->persist($tour);
$em->flush();
return $this->redirectToRoute('manage_tour');
}
else {
return $this->render('#HearWeGoHearWeGo/Manage/tour/approveonetour.html.twig', array('tour' => $tour));
}
}
In View:
{% extends('admin/admin.html.twig') %}
{% block mainpageheader %}
<h1 class="page-heading">APPROVE TOUR</h1>
{% endblock %}
{% block mainpagecontainerheader %}
<h3 class="block-title">Approve {{ tour.name }}</h3>
{% endblock %}
{% block mainpagecontainer %}
<div class="block">
<div class="block-content">
<table class="table">
<thead>
<tr>
<th class="text-center" style="width: 50px;">#</th>
<th style="width:15%">Name</th>
<th style="width:15%">Company</th>
<th style="width:15%">Destination</th>
<th style="width:20px">Start Date</th>
<th style="width:20px">End Date</th>
<th>Price</th>
<th>Discount</th>
<th style="width:40%">Info</th>
<th style="width:20px">Submission Date</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center">{{ tour.id }}</td>
<td>{{ tour.name }}</td>
<td>{{ tour.company.name }}</td>
<td>{{ tour.destination.name }}</td>
<td>{{ tour.startdate|date('Y-m-d') }}</td>
<td>{{ tour.enddate|date('Y-m-d') }}</td>
<td>{{ tour.price }}</td>
<td>{{ tour.discount }}</td>
<td>{{ tour.info|raw }}</td>
<td>{{ tour.createdAt|date('Y-m-d') }}</td>
</tr>
</tbody>
</table>
<form action="{{ path('approve_one_tour',{'id':tour.id}) }}" method="POST">
<input type="submit" class="btn btn-primary" value="Approve"/>
</form>
</div>
</div>
{% endblock %}
When the button is clicked, nothing happens
Because I only want to show the data of a Tour entity object, not allow the user to edit it, so I think I needn't create a Form Type that adds editable and reusable attributes. The only thing I need is a button, when I click the button, the only attribute of Tour entity needs changing is status, from false (default) to true. Is there any way? If any, please help fix my code above
First of all use $request->getMethod()== instead of $request if you want to check the request method.
You can create a form with just a submit button like so.
//in your controller
protected function createForm(){
$ff = $this->get('form.factory'); // get the form factory service, or inject it in
$builder = $ff->createBuilder('form');
$builder->add('submit', 'submit');
return $builder->getForm();
}
public function approveOneTourAction(Request $request, $id){
$form = $this->createForm();
$form->handleRequest($request);
if($form->isValid() && $form['submit']->isClicked()){
// ... do what you want with the tour here
}
return $this->render('#HearWeGoHearWeGo/Manage/tour/approveonetour.html.twig', array('tour' => $tour, 'form' => $form->createView()));
}
Then render the form passed as form to your template as explained in Symfony forms Documentation

View not populate data after dropdown data selection

I am work on MVC 5 and i fill a dropdown with state name of Country through ViewData and also in my view page i show the every state record. But i want, After selection of Dropdown value in view show only selected state value. this is my code that's not working
Controller
public ActionResult Index(int? id)
{
ViewData["State"] = new SelectList(db.state, "state_id", "name");
if (id!=null)
return View(db.state.Where(x => x.state_id == id));
else
return View(db.state.ToList());
}
View
#Html.DropDownList("ddlstate", (SelectList)ViewData["State"], "Select State", new { onchange = "Index(this.value);", #class = "form-control" })
<table class="table" id="statedetails">
<thead>
<tr>
<th>
State ID
</th>
<th>
State Name
</th>
<th>
City
</th>
<th>
Population
</th>
<th>
Education %
</th>
<th></th>
</tr>
</thead>
#foreach (var item in Model)
{
<tbody>
<tr>
<td>
#Html.DisplayFor(modelItem => item.stateid)
</td>
<td>
#Html.DisplayFor(modelItem => item.statename)
</td>
<td>
#Html.DisplayFor(modelItem => item.city)
</td>
<td>
#Html.DisplayFor(modelItem => item.population)
</td>
<td>
#Html.DisplayFor(modelItem => item.eduction)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.offer_id }) |
#Html.ActionLink("Details", "Details", new { id = item.offer_id }) |
#Html.ActionLink("Delete", "Delete", new { id = item.offer_id })
</td>
</tr>
</tbody>
}
</table>
javascript
<script type="text/javascript">
function Index(id) {
$.ajax({
url: "#Url.Action("Index","State")",
type: "POST",
data: { "id": id }
});
}
</script>

AngularJS Error

I got this error in inspector:
Error: [ngRepeat:dupes] http://errors.angularjs.org/1.2.9/ngRepeat/dupes?p0=subject%20in%20subjects&p1=string%3A%D0%90%D1%81%D1%82%D1%80%D0%BE%D0%BD%D0%BE%D0%BC%D0%B8%D1%8F
at Error (<anonymous>)
at http://vedomosti/js/angular.min.js:6:449
at http://vedomosti/js/angular.min.js:184:445
at Object.fn (http://vedomosti/js/angular.min.js:99:371)
at h.$digest (http://vedomosti/js/angular.min.js:100:299)
at h.$apply (http://vedomosti/js/angular.min.js:103:100)
at f (http://vedomosti/js/angular.min.js:67:98)
at E (http://vedomosti/js/angular.min.js:71:85)
at XMLHttpRequest.v.onreadystatechange (http://vedomosti/js/angular.min.js:72:133) angular.min.js:84
But I don't understand where my mistake...
I'm writing an application for school. I have table school in MySQL.
With fields:
id, name, 1,2,3,4,5,6,7,8,9,10,11
1,2,3,4... it's classes and they are have information about subjects. Each class have their subjects. Now I'm writing part, in which user can set subjects into classes. 1 to 10 classes all works good. But when I click "load subjects from 11 class", I get this error.
This table with subjects:
div class="large-6 column">
<label>Предметы {{class}} класса</label>
<table>
<thead>
<tr>
<th style="width: 200px;">Предмет</th>
<th style="width: 200px;">Изменить</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="subject in subjects">
<td>{{subject}}</td>
<td><a>изменить</a></td>
</tr>
</tbody>
</table>
</div>
And button for load information other classes:
<button class="button success tiny" ng-click="getSCLASS()">получить</button>
And function for this button:
$scope.getSCLASS = function(){
$http.post("/index.php/panel/getSCLASS", {class:$scope.class}).success(function(data){
$scope.subjects = data;
$scope.s_subjects = true;
});
}
From 1 to 10 classes - all works good. But with 11 class it's not work. I don't understand where my mistake.
Sorry for my English :|
See this and try this:
<div class="large-6 column">
<label>Предметы {{class}} класса</label>
<table>
<thead>
<tr>
<th style="width: 200px;">Предмет</th>
<th style="width: 200px;">Изменить</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="subject in subjects track by $index">
<td>{{subject}}</td>
<td><a>изменить</a></td>
</tr>
</tbody>
</table>
</div>