C# Class Bloom.Book.BookData

Show file Open project: BloomBooks/BloomDesktop Class Usage Examples

Public Properties

Property Type Description
KeysOfVariablesThatAreUrlEncoded HashSet

Private Properties

Property Type Description
GatherAttributes void
GatherDataItemsFromCollectionSettings DataSet
GatherDataItemsFromXElement void
GetOrCreateDataDiv System.Xml.XmlElement
MigrateData void
PossiblyCopyFromAnotherLanguage string
RemoveDataDivElementIfEmptyValue void
SendDataToDebugConsole void
SetInnerXmlPreservingLabel void
SetNodeXml void
SetUpDisplayOfTopicInBook void
SynchronizeDataItemsFromContentsOfElement DataSet
TextOfInnerHtml string
UpdateAttributes void
UpdateBookInfoTags void
UpdateCredits void
UpdateDomFromDataSet void
UpdateImageFromDataSet bool
UpdateIsbn void
UpdateSingleTextVariableInDataDiv void
UpdateSingleTextVariableInDataDiv void
UpdateTitle void
UpdateVariablesAndDataDiv void

Public Methods

Method Description
AddDataDivBookVariable ( string key, string lang, string form ) : void
BookData ( HtmlDom dom, CollectionSettings collectionSettings, Action updateImgNodeCallback ) : System
GetFirstAlternativeForm ( SIL.Text.MultiTextBase alternatives ) : LanguageForm
GetMultiTextVariableOrEmpty ( string key ) : SIL.Text.MultiTextBase
GetVariableOrNull ( string key, string writingSystem ) : string
GetWritingSystemCodes ( ) : string>.Dictionary
PrettyPrintLanguage ( string code ) : string

Give the string the user expects to see as the name of a specified language. This routine uses the user-specified name for the main project language. For the other two project languages, it explicitly uses the appropriate collection settings name for that language, though currently this gives the same result as the final default. This will find a fairly readable name for the languages Palaso knows about and fall back to the code itself if it can't find a name. Most names are not yet localized.

RemoveAllForms ( string key ) : void
RemoveSingleForm ( string key, string lang ) : void
Set ( string key, string value, bool isCollectionValue ) : void
Set ( string key, string value, string lang ) : void
SetMultilingualContentLanguages ( string language2Code, string language3Code ) : void
SuckInDataFromEditedDom ( HtmlDom dom ) : void

Create or update the data div with all the data-book values in the document

SynchronizeDataItemsThroughoutDOM ( ) : void
UpdateDomFromDataset ( ) : void

given the values in our dataset, push them out to the fields in the pages

UpdateVariablesAndDataDivThroughDOM ( BookInfo info = null ) : void

Private Methods

Method Description
GatherAttributes ( DataSet data, XmlElement node, string key ) : void
GatherDataItemsFromCollectionSettings ( CollectionSettings collectionSettings ) : DataSet
GatherDataItemsFromXElement ( DataSet data, XmlNode sourceElement, string>.HashSet itemsToDelete = null ) : void

walk through the sourceDom, collecting up values from elements that have data-book or data-collection or data-book-attributes attributes.

GetOrCreateDataDiv ( ) : XmlElement
MigrateData ( DataSet data ) : void
PossiblyCopyFromAnotherLanguage ( XmlElement element, string languageCodeOfTargetField, DataSet data, string key ) : string

In some cases, we're better off copying from another national language than leaving the field empty.

This is a tough decision. Without this, if we have, say, an English Contributors list but English isn't the N1 (L2), then the book won't show it at all. An ideal solution would just order them and then "display the first non-empty one", but that would require some java script... not something could be readily done in CSS, far as I can think. For now, I *think* this won't do any harm, and if it does, it's adding data, not losing it. Users had complained about "losing" the contributor data before.

RemoveDataDivElementIfEmptyValue ( string key, string value ) : void
SendDataToDebugConsole ( DataSet data ) : void
SetInnerXmlPreservingLabel ( string key, XmlElement node, string form ) : void

some templates have a element that javascript turns into a bubble describing the field these labels are temporary, so the go away and are not saved to data-book. But when we then take an xmatter template page and replace the contents with what was in data-book, we don't want to clobber the elements that are already in there. BL-3078

SetNodeXml ( string key, string form, XmlNode node ) : void
SetUpDisplayOfTopicInBook ( DataSet data ) : void

Topics are uni-directional value, reactâ„¢-style. The UI tells the book to change the topic key, and then eventually the page/book is re-evaluated and the appropriate topic is displayed on the page. To differentiate from fields with @data-book, which are two-way, the topic on the page instead has a @data-derived attribute (in the data-div, it is still a data-book... perhaps that too could change to something like data-book-source, but it's not clear to me yet, so.. not yet). When the topic is changed, the javascript sends c# a message with the new English Key for the topic is set in the data-div, and then the page is re-computed. That leads to this method, which grabs the english topic (which serves as the 'key') from the datadiv. It then finds the placeholder for the topic and fills it with the best translation it can find.

SynchronizeDataItemsFromContentsOfElement ( XmlNode elementToReadFrom, string>.HashSet itemsToDelete ) : DataSet

Go through the document, reading in values from fields, and then pushing variable values back into fields. Here we're calling "fields" the html supplying or receiving the data, and "variables" being key-value pairs themselves, which are, for library variables, saved in a separate file.

TextOfInnerHtml ( string input ) : string

The data we extract into title fields of _dataSet is the InnerXml of some XML node. This might have markup, e.g., making a word italic. It will also have the amp, lt, and gt escaped. We want to reduce it to plain text to store in bookInfo.

UpdateAttributes ( DataSet data, XmlElement node, string key ) : void
UpdateBookInfoTags ( BookInfo info ) : void
UpdateCredits ( BookInfo info ) : void
UpdateDomFromDataSet ( DataSet data, string elementName, XmlDocument targetDom, string>.HashSet itemsToDelete ) : void

Where, for example, somewhere on a page something has data-book='foo' lang='fr', we set the value of that element to French subvalue of the data item 'foo', if we have one.

UpdateImageFromDataSet ( DataSet data, XmlElement node, string key ) : bool

Given a node in the content section of the book that has a data-book attribute, see if this node holds an image and if so, look up the url of the image from the supplied dataset and stick it in there. Handle both img elements and divs that have a background-image in an inline style attribute. At the time of this writing, the only image that is handled here is the cover page. The URLs of images in the content of the book are not known to the data-div. But each time the book is loaded up, we collect up data from the xmatter and stick it in the data-div(in the DOM) / dataSet (in an object here in code), stick in a blank xmatter, then push the values back into the xmatter.

UpdateIsbn ( BookInfo info ) : void
UpdateSingleTextVariableInDataDiv ( string key, SIL.Text.MultiTextBase multiText ) : void

I (jh) found this labelled UpdateSingleTextVariableThrougoutDom but it actually only updated the datadiv, so I changed the name.

UpdateSingleTextVariableInDataDiv ( string key, string writingSystemId, string form ) : void

I (jh) found this labelled UpdateSingleTextVariableThrougoutDom but it actually only updated the datadiv, so I changed the name.

UpdateTitle ( BookInfo info = null ) : void
UpdateVariablesAndDataDiv ( XmlNode elementToReadFrom, BookInfo info = null ) : void

Create or update the data div with all the data-book values in the document

Method Details

AddDataDivBookVariable() public method

public AddDataDivBookVariable ( string key, string lang, string form ) : void
key string
lang string
form string
return void

BookData() public method

public BookData ( HtmlDom dom, CollectionSettings collectionSettings, Action updateImgNodeCallback ) : System
dom HtmlDom Set this parameter to, say, a page that the user just edited, to limit reading to it, so its values don't get overriden by previous pages. /// Supply the whole dom if nothing has priority (which will mean the data-div will win, because it is first)
collectionSettings Bloom.Collection.CollectionSettings
updateImgNodeCallback Action This is a callback so as not to introduce dependencies on ImageUpdater & the current folder path
return System

GetFirstAlternativeForm() public method

public GetFirstAlternativeForm ( SIL.Text.MultiTextBase alternatives ) : LanguageForm
alternatives SIL.Text.MultiTextBase
return LanguageForm

GetMultiTextVariableOrEmpty() public method

public GetMultiTextVariableOrEmpty ( string key ) : SIL.Text.MultiTextBase
key string
return SIL.Text.MultiTextBase

GetVariableOrNull() public method

public GetVariableOrNull ( string key, string writingSystem ) : string
key string
writingSystem string
return string

GetWritingSystemCodes() public method

public GetWritingSystemCodes ( ) : string>.Dictionary
return string>.Dictionary

PrettyPrintLanguage() public method

Give the string the user expects to see as the name of a specified language. This routine uses the user-specified name for the main project language. For the other two project languages, it explicitly uses the appropriate collection settings name for that language, though currently this gives the same result as the final default. This will find a fairly readable name for the languages Palaso knows about and fall back to the code itself if it can't find a name. Most names are not yet localized.
public PrettyPrintLanguage ( string code ) : string
code string
return string

RemoveAllForms() public method

public RemoveAllForms ( string key ) : void
key string
return void

RemoveSingleForm() public method

public RemoveSingleForm ( string key, string lang ) : void
key string
lang string
return void

Set() public method

public Set ( string key, string value, bool isCollectionValue ) : void
key string
value string
isCollectionValue bool
return void

Set() public method

public Set ( string key, string value, string lang ) : void
key string
value string
lang string
return void

SetMultilingualContentLanguages() public method

public SetMultilingualContentLanguages ( string language2Code, string language3Code ) : void
language2Code string
language3Code string
return void

SuckInDataFromEditedDom() public method

Create or update the data div with all the data-book values in the document
public SuckInDataFromEditedDom ( HtmlDom dom ) : void
dom HtmlDom This is either the whole document, or a page div that we just edited and want to read from.
return void

SynchronizeDataItemsThroughoutDOM() public method

public SynchronizeDataItemsThroughoutDOM ( ) : void
return void

UpdateDomFromDataset() public method

given the values in our dataset, push them out to the fields in the pages
public UpdateDomFromDataset ( ) : void
return void

UpdateVariablesAndDataDivThroughDOM() public method

public UpdateVariablesAndDataDivThroughDOM ( BookInfo info = null ) : void
info BookInfo
return void

Property Details

KeysOfVariablesThatAreUrlEncoded public property

public HashSet KeysOfVariablesThatAreUrlEncoded
return HashSet