Proprieties added at run time but when i add Content and publish it shows at the front end only after i rebuild - umbraco7

I'm using Umbraco 7 and i dynamically add proprieties to a tab called
Master & Detail Last Section
using this logic var x = 0;
foreach (var item in multiUrlPickerDyn)
{ var tab = dt.PropertyTypeGroups.LastOrDefault(t => t.Name == "Master & Detail Last Section");
var pt = dt.getPropertyType(item.Name + "m" + x) ?? dt.AddPropertyType(sidebar, item.Name + "m" + x, item.Name + " 'Master'");
pt.PropertyTypeGroup = tab.Id;
pt.Save();
pt = dt.getPropertyType(item.Name + "d" + x) ?? dt.AddPropertyType(sidebar, item.Name + "d" + x, item.Name + " 'Details'");
pt.PropertyTypeGroup = tab.Id;
pt.Save();
x++;
}
the proprieties are added and i can see them in the back office and everything is cool
but when i but content in them and publish it but it does not show up in the front end
it shows only after i rebuild my project the the list item shows before build but the content does not
after i rebuild every thing shows up does anyone know why ?
please help me i'm stuck

i was searching at the wrong direction was error getting the data from the back office
i was using
#Umbraco.Field(item.Name + "m" + x) wont work on run time
use this
var currentNode = umbraco.presentation.nodeFactory.Node.GetCurrent();
#currentNode.GetProperty(item.Name + "m" + x).Value;
UPDATE
this answer and this approach is all wrong don't add anything dynamic at run time its a bad practice yo can make the user add documents type from the Umbraco back office and using Currentpage.child list them in the view as an umbraco newbie im really sorry for asking and answering while im not that good.

Related

Without a click event, determine element id or simulate a click event on a material ui button base and populate it with a character

I am writing a modified TicTacToe game where the user has to enter a correct response before their selected square receives an "O" or "X". I have this working fine with two live players on the same computer.
When I add the ability for one player to play against an automated response I am having trouble placing the "X". I can calculate the best square(row and column) to place the, "X", but am having trouble displaying it on the board. Below is the code that displays the buttons. The board layout can be a square of any number between 3 and 10.
I track the coordinates (data-coord) of each square but do not know how to use the row and column to place a square in the button group. I do not have a click event for the automated user but if there was a way to simulate the click event at the selected location then I could place the "X" similar to how the live user's selection is updated. Can you please provide any suggestions for doing this?
const boardgui = board.map((row, rowId) => {
const columns = row.map((column, columnId) => (
<Grid key={columnId} item>
<ButtonBase >
<Paper
onClick={(e) => {
clickSquareHandler(e);
}}
elevation={4}
data-coord={rowId + ':' + columnId}
className={classes.Paper}>
<Icon
className={classes.Icon}
style={{fontSize: 78}}>
</Icon>
</Paper>
</ButtonBase>
</Grid>
));
return (
<Grid
key={rowId}
className={classes.Grid}
container
spacing={2}>
{columns}
</Grid>)
})
My son was able to resolve this for me. Two steps.
Added the following line right below the data-coord in the jsx.
id={"Square" + rowId.toString() + columnId.toString()}
Added the following code to update the square. Note that the location of the selected square to be updated was determined with another algorithm. One of my problems was that I thought I needed to simulate a click but turned out not to be the case. I just needed to get the element by id, get the child property and then assign an "X" (ie 'close') to the innerHTML.
let x = selectSquare.x;
let y = selectSquare.y;
let squareId = "Square" + x.toString() + y.toString();
console.log ("Board - automaticMover - squareId = ", squareId)
let squareElement = document.getElementById(squareId);
console.log ("Board - automaticMover - doc = ", squareElement)
let target = squareElement;
console.log ("Board - automaticMover - target = ", target)
let parent = squareElement.parentElement;
console.log ("Board - automaticMover - parent = ", parent)
let child = squareElement.children[0];
console.log ("Board - automaticMover - child = ", child)
board[x][y] = 'X'
child.innerHTML = 'close';

tmap:: faceted animated map: How to suppress title when custom label given

I have created an animated faceted map using tmap:: tm_facets along with custom panel labels. How do I avoid that the argument that is used to facet is shown as additional title? I only want the custom label in the panel.
Minimum example:
rm(list=ls(all=TRUE))
library(tmap)
library(spData)
urb_anim = tm_shape(world) + tm_polygons() +
tm_shape(urban_agglomerations) + tm_dots(size = "population_millions") +
tm_facets(along = "year", free.coords = FALSE) +
tm_layout(panel.labels = c("custom label1", "custom label2"))
That gives me the following result:
When I try to reproduce the example for an animated map from here: https://geocompr.robinlovelace.net/adv-map.html I also don't get the titles in a panel as in the example but outside the plot in the top left corner.
I found the answer myself:
Using the by instead of the along argument with tm_facets worked for me when setting ncol =1 and nrow = 1 and saving the the created map using tmap_animation. So the code should be:
urb_anim = tm_shape(world) + tm_polygons() +
tm_shape(urban_agglomerations) + tm_dots(size = "population_millions") +
tm_facets(by = "year", free.coords = FALSE, ncol=1, nrow=1) +
tm_layout(panel.labels = c("custom label1", "custom label2"))

Form location/size FMX - Win32

i'm building an FMX app for Win32 (one form only) with C++ Builder. I'd like the program to remember where it's form was located on the users screen and it's size (it is resizeable) for the next time the user runs it.
Can someone point me in the right direction?
thanks,
relayman
UPDATE: Thanks Sam. I did what you said but wrote the position info to an SQLite db instead of text file. The db has a table named "pos" with 5 integer fields. 4 are the positions and 1 is named "item" and is just to facilitate my update query (I'm not sql expert by long shot). Note, the code below needs try/catch improvements and some tests to make sure form coordinates are valid.
This code is in the form OnShow event:
TFDQuery *query2;
query2 = new TFDQuery(NULL);
query2->Connection = Form1->FDConnection1;
query2->SQL->Text = "SELECT * FROM pos";
query2->Open();
Form1->Left = query2->FieldByName("left")->AsInteger;
Form1->Top = query2->FieldByName("top")->AsInteger;
Form1->Width = query2->FieldByName("width")->AsInteger;
Form1->Height = query2->FieldByName("height")->AsInteger;
query2->Close();
query2->DisposeOf();
This code is in the form OnClose event:
TFDQuery *queryUPDATE;
queryUPDATE = new TFDQuery(NULL);
queryUPDATE->Connection = Form1->FDConnection1;
queryUPDATE->SQL->Text = "UPDATE pos set left = '" + IntToStr(Form1->Left) + "', top = '" + IntToStr(Form1->Top) + "', width = '" + IntToStr(Form1->Width) + "', heigth = '" + IntToStr(Form1->Height) + "' WHERE item = '1'";
queryUPDATE->ExecSQL();
queryUPDATE->Close();
queryUPDATE->DisposeOf();
OnClose save the position, with, height, state, ... into an INI file. OnCreate restore all that info

Google Sheets - Multiple dependent drop-down lists

I am trying to create a dependent list as described and answered (with a script) here.
I would like to achieve that if selecting a certain value (e.g. "First") from a cell in column 1, then the drop-down options from the next cell in the same row should offer a range of values from the column in a different sheet with the same heading as the value in the first - left - cell (i.e. the first sheet is called "Selector" - in which there are dropdowns, in the second sheet called "KAT" I have the options for these dropdowns). This should then be possible for every row depending on the value of each first cell of the row.
I have tried to use and adapt the suggested script and have reviewed the sample files in the article but I apparently lack some basic understanding of the script to be able to adapt and implement it properly.
Could anybody kindly help me with making this dynamic dropdown work properly?
Just to clarify my final intention: I would like to have this script working first to be able to use it on multiple files. My final goal, though, is to make self-filling dropdown lists and selectors, so that I could simply fill in the data in the "Selector" sheet and would then be able to select these same values later in the cells below (depending on the name (value) of the first cell in the row = first cell of the column holding validation range). I hope to be able to achieve this by using either Pivot table or any other formula in the "KAT" sheet that would aggregate my data from "Selector" sheet and feed them back as drop-down options ...).
Thank you for your help.
See the example sheet here
Code I used (as above):
function onEdit()
{
var ss = SpreadsheetApp.getActiveSpreadsheet(),
sheet = ss.getActiveSheet(),
name = sheet.getName();
if (name != 'Selector') return;
var range = sheet.getActiveRange(),
col = range.getColumn();
if (col != 1) return;
var val = range.getValue(),
dv = ss.getSheetByName('KAT'),
data = dv.getDataRange().getValues(),
catCol = data[0].indexOf(val),
list = [];
Logger.log(catCol)
for (var i = 1, len = 100; i < len; i++) // Problem is here, you have too many items in list! Cannot have more 500 items for validation
list.push(data[i][catCol]);
var listRange = dv.getRange(2,catCol +1,dv.getLastRow() - 1, 1)
Logger.log(list)
var cell = sheet.getRange(range.getRow(), col-1)
var rule = SpreadsheetApp.newDataValidation()
.requireValueInRange(listRange) // Use requireValueIn Range instead to fix the problem
.build();
cell.setDataValidation(rule);
Logger.log(cell.getRow())
}
This question deals with dynamic dropdown lists. A previous question and answer on StackOverflow (Google Sheets - Dependent drop-down lists) were referenced, and code from that answer was being unsuccessfully re-purposed.
The code in the question was not working for one reason: Line 20
var cell = sheet.getRange(range.getRow(), col-1)
In the referenced code, the dropdown list begins in Column F (col=6). The dependant dropdowns ranged to the left so the definition of the dependant column was "col-1". In the questioner's scenario, the dropdown list begins in Column A (col=1) and the dependant dropdowns range from left to right. However, this line of code was not changed to take into account the different layout. Rather than "col-1", it should be "col+1".
Other matters
In addition to this, lines 16 and 17 perform a loop to create an array that might be used for the dependant dropdown. However the loop is redundant because the dropdown is actual defined by creating and assigning a range on the "KAT" sheet.
Cell A2 of KAT includes a formula:
=sort(unique(Selector!$A$2:$A),1,true)
This may appear to be useful because it automatically adds any new dropdown value entered in "Selector" to a list of values in KAT. In reality it is unproductive, because the dependant dropdown build by the code works vertically rather than horizontally. So an additional row added to KAT does not, of itself, contribute to building the dependant dropdown.
The following code works to build the dependant drop down list. I have deliberately left a number of "Logger" entries in the code to assist the questioner in understanding how the code works.
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var name = sheet.getName();
if (name != 'Selector') return;
var range = sheet.getActiveRange();
var col = range.getColumn();
var dropdownrow = range.getRow(); // added for debugging and informationm
if (col != 1) return;
var val = range.getValue();
Logger.log("the cursor is in 'Selector' in cell = " + range.getA1Notation()); //DEBUG
Logger.log("That's row " + dropdownrow + ", and column " + col + ". The value selected = " + val); // DEBUG
var dv = ss.getSheetByName('KAT');
var data = dv.getDataRange().getValues();
var catCol = data[0].indexOf(val);
var list = [];
var KAT_data = dv.getDataRange();
var KAT_data_len = KAT_data.getLastRow(); // added to give 'for' loop a sensible range
Logger.log("The data range on KAT is " + KAT_data.getA1Notation() + ", and the last row of data = " + KAT_data_len); //DEBUG
Logger.log("KAT data = '" + data + "'"); // DEBUG
Logger.log("Found the dropdown cell value of '" + val + "' in KAT as item #" + catCol); //DEBUG
for (var i = 1, len = KAT_data_len; i < len; i++) { // Irrelevant because the data validation range is obtained by defining a range on KAT
// Problem is here, the unique command in A2 creates a blank row
// Logger.log("i="+i+", data = "+data[i][catCol]); // DEBUG
list.push(data[i][catCol]);
}
var listRange = dv.getRange(2, catCol + 1, dv.getLastRow() - 1, 1);
Logger.log("FWIW, this is the list after the loop= " + list); // DEBUG
Logger.log("The contents for the new data validation range (taken from KAT) is " + listRange.getA1Notation()); // DEBUG
Logger.log("The new validation range gets added to col = " + (col + 1)); // DEBUG
//var cell = sheet.getRange(range.getRow(), col-1); // governs the next validation range. Example validation worked right to left, but this sheet works left to right. So must ADD 1, not subtract 1.
var cell = sheet.getRange(range.getRow(), col + 1);
Logger.log("The cell to be assigned the new validation range will be " + cell.getA1Notation()); // DEBUG
var rule = SpreadsheetApp.newDataValidation().requireValueInRange(listRange).build(); // Build validation rule
cell.setDataValidation(rule); // assign validation range to new cell
}
Is this code worthwhile?
The code, as written and referenced, is limited to creating only one level of dependant dropdowns. To this extent it has very limited value. A different approach to creating dependant dropdowns is justified.
"How do you do dynamic / dependent drop downs in Google Sheets?" on StackOverflow has been a meeting place for discussing and updating techniques for dynamic dependant dropdowns since 2014. The latest update was in February 2018 by Max Makhrov. Thye code described here may be useful for the questioner.

Getting row data from SlickGrid when using the pager plugin

I'm using SlickGrid with the pager plugin. My intent is to display line items in SlickGrid and allow the user to double click on a row to get more detail. I have code that seems to work fine but it feels as though I'm doing this the hard way:
grid.onDblClick.subscribe(function(e, args) {
var selectedIndex = parseInt(grid.getSelectedRows());
var pageInfo = dataView.getPagingInfo();
var pageSize = pageInfo.pageSize;
var pageNum = pageInfo.pageNum;
var idx = pageSize*pageNum + selectedIndex;
var asset = rows[idx].assetName;
alert("Selected Asset is " + asset);
});
I've seen other questions posted where people did a grid.getData()[selectedIndex] or a dataView.getItemById(selectedIndex), but since selectedIndex is always a 0 to something number, I always got data from the first page in my list regardless of which page I was on. Is there a direct way to map a selected index on a page to the actual row in the data array? Again, the code above seems to work fine - just feels like I'm missing an obvious method somewhere.
grid.onDblClick.subscribe(function(e, args) {
alert("Selected asset is " + args.item);
alert("Or " + grid.getData().getItem(args.row));
alert("Or " + grid.getDataItem(args.row));
});

Resources