How to loop through Angular mat-radio-buttons to delete values? - angular-material

I've already asked a bunch of experienced developers and they basically told me its impossible without using many if then else statements. Here's my hardcoded example that works but Im looking for something more efficient, something elegant. There are 10 questions, if I answer all of them but decide to go back and change question #5 for example, I want to delete all questions' answers after that question, doesnt matter which question you are on, basically if you go backwards on any question, delete everything after.In Angular, this is more difficult than you think. This is the hard coded of what currently works:
clearAllQuestions() {
if (this.q1 == 'N') {
this.q2 = '';
this.q3 = '';
this.q4 = '';
}
else if (this.q2 == 'Y') {
this.q3 = '';
this.q4 = '';
}
else if (this.q3 == 'Y') {
this.q4 = '';
}
Is there anyway to identify which question you are currently on to erase everything after that? Initially I thought loop through and array but didnt work. Here is an example of how the questions are constructed in HTML. Please assume q2-q4 also have the same format.
<div class="col-md-5">
<mat-radio-group class="ans-radio-group" [(ngModel)]="q1">
<!--<mat-radio-button class="ans-radio-button" (change)="ClearAllQuestions()"
*ngFor="let answer of answers" [value]="answer.key">-->{{ answer.value }}
</mat-radio-button>
</mat-radio-group>
</div>

Related

Page loading is slow in MVC Application

I have developed application in MVC using rojar view.it working fine but one of testing server rander the page in 4 seconds and on production server it takes 30-35 seconds.
Database on both the server are different nut code and number of records are same on both the server
foreach (var subcategpory in Model.category.RFP_SubCategories)
{
if (subcategpory.RFP_Questions.Any(q => q.SubCategoryId == subcategpory.SubCategoryId))
{
<div class="vendor-block">
<div class="vendor-title border-bottom">
<h6>#subcategpory.SubCategory</h6>
<p>Selected:<span class="selectedQuestion" id="selectedQuestion_#subcategpory.SubCategoryId">0</span></p>
</div>
<ul class="vendor-list">
#if (Model.category.RFP_Questions != null)
{
foreach (var que in subcategpory.RFP_Questions.Where(q => q.SubCategoryId == subcategpory.SubCategoryId))
{
bool IsChecked = Model.category.RFP_SelectedQuestions.Any(sq => sq.QuestionId == que.QuestionId);
}
}
</ul>
</div>
}
}
Can you please suggest any way to resolve the issue and actual reason.
Thanks,
Vishal
I would check that you have the same indexes on both databases as possibly there has been an index created on the test server which is missing on the live one.
Another obvious point would be that the live server may have more resource contention due to other things accessing the server. This situation could also be remedied by having correct indexes allowing the query to complete quickly.
I would check the SubCategoryId and QuestionId fields have appropriate indexes.
You could also look at the statistics and ensure they are up-to-date on the live server. This: https://msdn.microsoft.com/en-us/library/ms173804.aspx may be worth looking at.
You can avoid deferred execution. Try this:
Don't use Model.category.RFP_SubCategories directly.Instead:
var lst=Model.category.RFP_SubCategories.ToList()
and loop through using lst
You can also change
foreach (var que in subcategpory.RFP_Questions.Where(q => q.SubCategoryId == subcategpory.SubCategoryId))
{
bool IsChecked = Model.category.RFP_SelectedQuestions.Any(sq => sq.QuestionId == que.QuestionId);
}
to
var qstnsList= subcategpory.RFP_Questions.Where(q => q.SubCategoryId == subcategpory.SubCategoryId).ToList()
and use qstnsList in foreach loop if data exist.
Try this and do tell me if it saved time or not.

WoW API / Lua - Math.Random(#,#)

Always feel like I'm making something far more complicated than it has to be. I'm currently playing around with the WoW addon, Tongues, in hope of make a custom dialect filter - which is quite easy of course, very noob-friendly. At this point, there is one thing I want to accomplish-- something of which feels to have the implications far beyond this -- that is just novelty, but before I give up completely (lots of hours trying different things with no headway) I was hoping someone could come by, get a cheap laugh and perhaps help me fix this if they understand my point. And who knows, posting this new helpless questions might bump me up to being able to finally upvote!
Tongues.Affect["Drunk"] = {
["substitute"] = {
[1] = merge({
{ ["([%a]+)(%A*)$"] = "%1 ...hic!"},
Tongues.Affect["Slur"]["substitute"][1]
});
};
["frequency"] = 100;
};
What this does is simply add on the "...hic!" to sendchatmessage(); I believe it is. The frequency part seems completely broken and only the GUI slider in the game matters for that. What I was hoping to accomplish was to repurpose this and make the "...hic!" an actual randomized word. Since the mod itself handles the chance that it happens, I figured all that is needed left is to replace the string with a function=X. It's, of course, intensely way over my head, but despite checking the Lua of several mods, nothing feels like "it will fit."
The best I could come up with,
Tongues.Affect["TESTAFFECT"] = {
["substitute"] = {
[1] = merge({
{ ["([%a]+)(%A*)$"] = function(b)
local rand = Math.Random(1,2)
if (rand == 1) then
b = "test1"
return b
elseif (rand == 2) then
b = "test2"
return b
end
end
Leaves a gloriously useless message in the error mod BugSack - of course my attempt is wrong, but there's no way to know how!
I'm assuming this is enough information - as I said, very user friendly mod without any need to understand how it really works (Although I'd love to ready study it after this "project")
Anyone? Regardless, thank you for your time in simply even reading this far.
Update: Downvotes, okay! That's cool too. A little unpredictable, but sure. The error is as follows
15x Tongues\Core\dialects.lua:172: attempt to index field 'Affect' (a nil value)
Tongues\Core\dialects.lua:172: in main chunk
Locals:
175 in dialects.lua is
Tongues.Affect["Wordcut"]["substitute"][1],
Which has nothing to do with what I'm trying to accomplish, and works just fine.
Sorry that my question was an inconvenience. I asked to the best of my ability and the best of my ability to articulate the question proved to be less then stellar. The example codes I had provided were the only way I could articulate showing what I was trying to do.
I was misinterpreting the error frame and discovered that behind the useless stack that calls an error where there is, in fact, none, is a stack that calls the error in syntax at the time that broke it.
I'm sharing my results, regardless if the community finds this useless. I learned a tremendous amount from this personally, which is the only incentive in that I asked for help.
Tongues.Affect["TEST"] = {
["substitute"] = {
[1] = {
["([%a]+)"] = function(a)
return a
end;
["(%A*)$"] = function(a,b)
local rand = math.random(1,2)
if (rand == 1) then
b = "test1"
return b
end;
if (rand == 2) then
b = "test2"
return b
end;
end;
};
};
};
Hope it helps someone out there - as expected, I made it more complicated than it had to be. Simply "jiggling" the symbols is all that was needed.

How to check if listbox is empty?

I want to do a check on a ListBox if it is empty, like:
if {Listbox.Items is empty} then
begin
Listbox.Items.Add('Item');
end else
begin
//do somthing else
end;
The part of the check if Listbox.Items or if Listbox are/is empty is a little hard for me. I tried to figure out a way how to do it, but I failed as I am still a beginner with Delphi. How can I implement that in Delphi XE5?
if listbox.items.count = 0 then
// it's empty
In Access VBA there is no ".items.count" property on a Listbox
I tried Me.ListBox.ListCount and .ListIndex to see if the List was empty.
ListCount was always 1 and ListIndex always -1 whether the list was empty or not (in my case).
To overcome that I used:
If Me.ListBox.ItemData(0) = "" then
Do Something
End If
This worked for me - hope this helps someone
I would reverse your if statement.
Personally I like the most code in the true part of my statement and the shorter code in the false part. For some reason it makes more sense to me.
So the code would look like:
If Listbox.items.count > 0
begin
//Do something else
end
else
Listbox.items.add('item');
Also if your true, or false, part only contains 1 line of code you don't need a begin..end. It's not wrong to have them but in my opinion it makes code easier to read if they aren't there ;)

The "Could not find row $id" error

A simple question about the getting started (Album) tutorial.
Its' about the deleteAction :
public function deleteAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if(!$id){
return $this->redirect()->toRoute('album');
}
$request = $this->getRequest();
if ($request->isPost()) {
$del = $request->getPost('del', 'No');
if($del == 'Yes'){
$id = (int) $request->getPost('id');
$this->getAlbumTable()->deleteAlbum($id);
}
return $this->redirect()->toRoute('album');
}
return array(
'id' => $id,
'album' => $this->getAlbumTable()->getAlbum($id)
);
}
From what I understand, when an album is deleted from the database, a redirection occurs just after that, to the /album/ route. If I comment (suppress) that redirection, an error "could not find row $id" occurs because getAlbum($id) then tries to retrieve the album that was just deleted, and thus no longer exists...
My question is : is there a way (like a conditional statement on the return array() or getAlbum()) to make things work without the redirection (which should aim at a success page btw)?
Thanks !
You need to understand the code. Don't blindly copy paste, understand what's happening there. What you're asking for makes literally no sense.
Once an album is deleted you should see an overview page or a "deleted success" page. This is completely for you to decide what you want to choose but in all cases the redirection is the way to go. There's still the forward() plugin, but all it does is to do the redirect internally. There's not really any advantage in doing this for the given use-case that you present.
If you want to return something else than a redirect, then by all means go ahead and return another ViewModel that points to a different template.
TL/DR: understand the code before you want to modify it.

How to edit the BibTeX .bst FUNCTION {format.names}?

After trying several .bst files I am still mostly satisfied with the layout of the ChicagoReedWeb.bst file. However, I don't like the handling of entries by the same author, eg:
If have looked at the ChicagoReedWeb.bst file but only understand some of the basics.
So how can I edit the code of the ChicagoReedWeb.bst file in such a way that it will print the author's full reference instead of the "--------" ?
OK, this is well outside my previous experience with BibTeX, but looking at the file, I get the impression that the name.or.dash section is replacing the name with a dash if it's the same as the previous one. I suggest trying replacing this code:
FUNCTION {name.or.dash}
{ 's :=
oldname empty$
{ s 'oldname := s }
{ s oldname =
{ "\rule[.6ex]{3em}{.05ex}"}
{ s 'oldname := s }
if$
}
if$
}
with this:
FUNCTION {name.or.dash}
{
}
If my understanding of the syntax is correct, this should simply remove the comparison and optional change, and leave the name as you want it.
A slightly tidier approach might be to take out the calls to name.or.dash in the places which you don't want them. That will give you more flexibility about whether you want a dash in place of, for example, a repeated book name.

Resources