how to remove chart completely in Angular - html

I have multiple charts in my home page and I have a search box to filter them by chart name.
when I filter particular chart I can delete that chart while it's begin filtered and it disappear from UI but some reason the chart that I just deleted still appear in the home page with the rest of the other charts when I unfiltered/removed all the text in the search box.
It got deleted in the backend but the deleted chart is still appearing in the front end. Also for some reason I can still search it again the one that I just deleted but this time I can not delete it again since it throw 404.
It only disappear completely when I refresh the browser. Any suggestion on how I can make the chart to disappear even after I unfiltered in the search box.
HTML
//Imported this component to display a list of chart
<ng-container *ngFor="let chart of charts">
<mc-chart-list [chart]="chart" [wsType]="workspace.type" (removeFromList)="onRemoveFromList($event)"></mc-chart-list>
</ng-container>
//I use this searchbar to filter by the name of the chart
<input class="input" matInput name="query" [formControl]="query" placeholder="Filter Workspace">
TS
#Input() chart: Chart;
workspace: Workspace;
private death$: Subject<void> = new Subject();
query: FormControl = new FormControl();
charts: Chart[] = [];
searchText: string;
ngOnInit(): void {
this.activatedRoute.paramMap.pipe(takeUntil(this.death$)).subscribe((paramMap) => {
const guid = paramMap.get('guid');
if (guid) {
this.workspaceService.getWorkspace(guid, this.isPublished).subscribe(ws => {
this.workspace = ws;
}, () => this.loading = false);
}
})
//For search bar
this.query.valueChanges
.pipe(takeUntil(this.death$))
.subscribe((value: string) => {
this.search(value);
});
}
search(searchText: string){
// reset
searchText = searchText.toLowerCase();
if (!searchText || searchText.length == 0) {
this.charts = this.workspace.charts;
}
// search
else {
this.charts = this.charts.filter(chart => chart.name.toLowerCase().indexOf(searchText) >= 0);
}
}
onRemoveFromList(id: number) {
const index = this.charts.findIndex(e => e.id === id);
if (index >= 0) {
this.charts.splice(index, 1);
}
I can do this.ngOnIt() inside the search funtion but I don't think that will be best way to do it so I'll be really appreciated if someone can help me fix this.

your workspace.charts have the all the charts.you are assigning value for charts from workspace.charts.In your onRemoveFromList function you only remove it from chart.but workspace.charts still have that removed value.then whenever you reset the search the removed values going in to the charts that is why you see those removed charts.
Solution: in your onRemoveFromList remove the chart from workspace.charts too.
onRemoveFromList(id: number) {
const index = this.charts.findIndex(e => e.id === id);
if (index >= 0) {
this.charts.splice(index, 1);
this.workspace.charts = this.workspace.charts.filter(e => e.id !== id);
}

Related

finding Text with specific format and delete it

I have a big google doc file with over 100 pages(with tables etc) and there is some reference text in that document in multiple locations reference texts are highlighted with the color "grey", I want to have a function that can find those colors/style in the table or paragraph and delete it. So Step 1 is finding it, and then deleting(removing those texts from the document) it in one go.
How we did it in MS Word is, we created custom styles and assign those styles to those "Remarks Text"(in grey) and in VBA we look for text matching the style name, and if it returns true than we delete those texts. As much i know about doc, there is no option to create custom styles.
Here is the code I am trying:-
function removeText()
{
var doc = DocumentApp.getActiveDocument()
var body = doc.getBody()
body.getParagraphs().map(r=> {
if(r.getAttributes().BACKGROUND_COLOR === "#cccccc")
{
//Don't know what to do next, body.removeChild(r.getChild()) not working
}
})
}
Can you guide me on how I can achieve this effectively please.
Thanks
Try this
body.getParagraphs().forEach( r => {
if( r.getAttributes().BACKGROUND_COLOR === "#cccccc" ) {
r.removeFromParent();
}
}
Reference
Paragraph.removeFromParent()
Google Apps Script hasn't a method to find text based on their style attributes, instead we need to get each part and in order to be able to get their attributes. The following example, if the format is applied to the whole paragraph, it is deleted, if not, it uses the regular expression for finding any single character ..
function removeHighlightedText() {
// In case that we want to remove the hightlighting instead of deleting the content
const style = {};
style[DocumentApp.Attribute.BACKGROUND_COLOR] = null;
const backgroundColor = '#cccccc';
const doc = DocumentApp.getActiveDocument();
const searchPattern = '.';
let rangeElement = null;
const rangeElements = [];
doc.getParagraphs().forEach(paragraph => {
if (paragraph.getAttributes().BACKGROUND_COLOR === backgroundColor) {
paragraph.removeFromParent();
// Remove highlighting
// paragraph.setAttributes(style);
} else {
// Collect the rangeElements to be processed
while (rangeElement = paragraph.findText(searchPattern, rangeElement)) {
if (rangeElement != null && rangeElement.getStartOffset() != -1) {
const element = rangeElement.getElement();
if (element.getAttributes(rangeElement.getStartOffset()).BACKGROUND_COLOR === backgroundColor) {
rangeElements.push(rangeElement)
}
}
}
}
});
// Process the collected rangeElements in reverse order (makes things easier when deleting content)
rangeElements.reverse().forEach(r => {
if (r != null && r.getStartOffset() != -1) {
const element = r.getElement();
// Remove text
element.asText().deleteText(r.getStartOffset(), r.getEndOffsetInclusive())
// Remove highlighting
// element.setAttributes(textLocation.getStartOffset(), textLocation.getEndOffsetInclusive(), style);
}
});
}

How to add simple click event with Vega-lite ObservableHQ?

When someone clicks on points on the data, I want call custom function to show some image or information.
I am using Vega-lite in ObservableHQ notebooks and couldn't find answer?
const chart = (type)=>{
return vl
.markCircle({size: 15, opacity: 0.9})
.autosize('fit')
.data(getData(type))
.encode(
vl.x().fieldQ('slice').title('Slice'),
vl.y().fieldQ('dice').title(type).scale({domain: [0, 1.0]}),
vl.color().field('algorithm').title('Algorithm'),
vl.tooltip(['slice', 'algorithm', 'dice'])
)
}
const types = ['DSC','SDSC_2mm']
const charts = []
types.map(type => {
charts.push(chart(type))
})
return vl.vconcat(vl.hconcat(charts)).render()
}
This is the code I have in notebook.
If you just care about click, you can do something like the first cell in this notebook: https://observablehq.com/#visnup/vega-lite-data-out
Specifically:
clicked = Generators.observe((notify) => {
const clicked = (event, {datum}) => notify(datum);
clickable.addEventListener("click", clicked);
return () => clickable.removeEventListener("click", clicked);
})
where clickable is the name of my chart from the other cell.
A better-than-clickable example would be to do the same thing for Vega-Lite selections. I've added that to the notebook too.
selected = Generators.observe((notify) => {
const signal = Object.keys(selectable.getState({ signals: (name) => name.match(/^sel\d+$/) }).signals)[0];
const selected = (selection, predicates) => {
const within = penguins.filter(d => {
for (const [key, [min, max]] of Object.entries(predicates))
if (isNaN(+d[key]) || d[key] < min || d[key] > max)
return false;
return true;
})
notify(within);
}
selectable.addSignalListener(signal, selected);
return () => selectable.removeEventListener(signal, selected);
})

how to show all the chips when it filtered in Angular

I'm really new developer working on existing code base and right now my task is to show all the chips inside the card when one particular chip is selected from Chip List but I'm not really sure how to modify this code so I would be really appreciate if I can get any help or suggestion.
So right now we have multiple cards that contain their own chips and a chips list that can filter cards based on their chips. When a user select a particular chip from Chip List, it filter all the cards and only show the cards that contain the selected chip.
Situation
right now, when particular chip are selected from Chip List, all the chips inside the card are disappear/filter except the one chip that user select.
Trying to achieve
I still want the card to show every chips that it contained and not just show only what is selected by user.
<!--- Cards List -->
<mc-workspace-card-list [workspaces]="filteredPubWorkSpaces"></mc-workspace-card-list>
<!-- Tags List -->
<mat-chip *ngFor="let tag of tagList" [selected]="tag.state"
(click)="tag.state = !tag.state; changeSelected('s', tag.tag)"
[ngStyle]="{'background-color':tag.state? 'mediumturquoise' : '' }">
<img class="super-icon" *ngIf="tag.superTag || tag.type == TagType.super"
src="/assets/images/icons/super-tag-icon.svg">
{{tag.tag}}
</mat-chip>
</mat-chip-list>
tagList: Tag[] = [];
chartSearchResults: Chart[] = [];
tagSearch: string[] = [];
filteredPubWorkSpaces = [];
ngOnInit(): void {
var superTags: Tag[] = [];
//get all the tags
this.tagService.getAllTagsByType('super').subscribe((sTags) => {
this.loading = true;
if (sTags) {
superTags = sTags;
}
});
this.tagService.getAllTagsByType('user').subscribe((tags) => {
if (tags) {
this.tagList = superTags.concat(tags);
}
this.loading = false;
});
search(value: string, tags?: string[]) {
if (!tags) {
tags = [];
}
this.loading = true;
this.chartSearchResults = [];
this.searchService.search(value, tags, 0, 50).subscribe((data) => {
if (data) {
this.filteredPubWorkSpaces = data.results;
for (let result of data.results) {
if (this.chartSearchResults.length < 10) this.chartSearchResults = this.chartSearchResults.concat(result.charts);
}
}
this.loading = false;
})
}
changeSelected(parameter: string, query: string) {
this.cdr.detectChanges();
const index = this.tagSearch.indexOf(query);
if (index >= 0) {
this.tagSearch.splice(index, 1);
}
else {
this.tagSearch.push(query);
}
this.search("", this.tagSearch);
}
Its not visible here, but either your mc-workspace-card-list component is filtering out what pills are shown (searched for), or your searchService.search() method is filtering out the pills, im guessing its the latter.
You need to modify the searchService.search() method to return the complete pill-lists on the workSpaces. If you edit and post the search method theres probably a line or two that needs to be changed

Multiple APIs are called with (change) in angular

On selecting any date and hitting enter an API call should be made. And there's a x icon in the input on clicking it, it should call the API with date 01/01/12 Also this has feature like if you type 2/3 and hit enter it will automatically make it 02/03/20. The problem is if the input is empty and if I hit Enter same API calls are made thrice.
But the feature should be like if you select a date then without hitting Enter an API call should be made. I can't just use change function because if 2/3 is typed and Tab is pressed then it will not adjust the date automatically and also multiple API calls on hitting Enter. Is there a way to stop multiple API calls?
(change)="startDate($event)" (keydown.enter)="CallAPI($event)"
startDate(event) {
if (event.target.value == '' || event.target.value == null)
this.cutoverFilterApi(event)
}
CallAPI(event) {
let data = event.target.value;
if (data != '' && data != null && data != "NaN/NaN/NaN") {
data = data;
} else {
data = "01/01/12";
}
this.httpService.getData('PATH' + data).subscribe((response: any) => {
this.dateChangeData = response.results;
this.rowData = response.results;
this.gridApi.setRowData(this.rowData);
});
}
You could keep the last valid value and avoid request if it is the same.
Something like this,
lastDate = null; // <- variable to keep last value
CallAPI(event) {
let data = event.target.value;
if (data != '' && data != null && data != "NaN/NaN/NaN") {
data = data;
} else {
data = "01/01/12";
}
// check if data is not the same as last request
if (this.lastDate === data) {
return;
}
this.lastDate = data; // <- update new request date
this.httpService.getData('PATH' + data).subscribe((response: any) => {
this.dateChangeData = response.results;
this.rowData = response.results;
this.gridApi.setRowData(this.rowData);
});
}
You can use this
(dateInput)="addEvent('input', $event)" (dateChange)="addEvent('change', $event)"
instead of
(change)="startDate($event)" (keydown.enter)="CallAPI($event)"
I have an example of angular material datepicker, which will make your code easier.
Reference link
I hope it is helpful for you. :)

Get the value of all checkbox when checkall checkbox is checked

I'am new to angularjs, I'm creating an application of attendance. When i check the checkall checkbox all the checkbox of name is also check and What i really wanted to achieve is to get the value of checked checkboxes. I'm done with checking all checkboxes. I just want to store all the value of checkboxes in an array. I can only get data when i check those checkboxes one by one. Thank you in advance.
In my html here is my code.
<ion-checkbox ng-model="Selected" ng-click="checkAll()">
<div class="wew">
Check All Checkbox
</div></ion-checkbox>
</label></div>
<table><tr><th><center>
List of Names
</center></th>
<th colspan="3">
Actions
</th></tr><tr><td><label>
<ion-checkbox ng-repeat="role in roles" ng-model="isChecked" ng-
change="format(isChecked,role,$index)"><div class="wew">
{{role}}
</div></ion-checkbox>
</label></td>
And in my controllers code. First this is my code where i get the list of names.
$http.post(link1, {section: section}).success(function(attendance){
for(a = 0; a<attendance.length; a++){
$scope.roles = [
attendance[0].Full_Name,
attendance[1].Full_Name,
attendance[2].Full_Name,
attendance[3].Full_Name,
attendance[4].Full_Name,
attendance[5].Full_Name,
attendance[6].Full_Name,
attendance[7].Full_Name,
attendance[8].Full_Name,
attendance[9].Full_Name,
]
}
})
.error(function(err) {
console.log(err)
})
And this is my code where i wanted to execute the checkall and automatically store the data in $scope.selected = []; if i click the check all checkbox..
$scope.checkAll = function () {
if ($scope.Selected) {
$scope.Selected = false;
} else {
$scope.Selected = true;
}
$scope.isChecked= $scope.Selected;
$scope.selected = [];
$scope.format = function (isChecked, role, $index) {
if (isChecked == true) {
$scope.selected.push(role);
}
else {
var _index = $scope.selected.indexOf(role);
$scope.selected.splice(_index, 1);
}
var students = $scope.selected;
console.log(students);
}
}
try this code
<script>
$(function(){
var numbers = $("input[type='checkbox']:checked").map(function(_, el) {
return $(el).val();
}).get();
});
</script>