[twdev] Re: New to TW - experienced dev - question

2020-07-02 Thread Guido B
This is an example of an ISBN without a cover: 9783858824875. It throws the 
following error: 

$:/plugins/ceebee/bookinfo/action-getbookinfo.js:36 Uncaught (in promise) 
TypeError: Cannot read property 'medium' of undefined
at eval ($:/plugins/ceebee/bookinfo/action-getbookinfo.js:36)

Thanks, Guido

Am Freitag, 3. Juli 2020 01:54:36 UTC+2 schrieb christia...@gmail.com:
>
> Hi Guido,
>
> If you can give me the ISBN number you used I'll give it a test and see 
> what I can do to catch the error.. Probably won't maintain this for long 
> though... I think its worth while trying to make the API call and JSON 
> inspections more generic so you could support other sources 
>
> Cheers
> CB
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/11beb374-28bf-4a5a-a567-1db96a154202o%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-07-02 Thread christia...@gmail.com
Hi Guido,

If you can give me the ISBN number you used I'll give it a test and see 
what I can do to catch the error.. Probably won't maintain this for long 
though... I think its worth while trying to make the API call and JSON 
inspections more generic so you could support other sources 

Cheers
CB

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/53b2dfce-a052-4a0b-97ae-beb2ecdc0ba4n%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-07-02 Thread TonyM
CB,

Great work and impressive. Perhaps you should package and publish in on the 
main thread. I am sure people there would like it.

I understand this only goes to openlibrary.org 

 is 
there a way to query other ISBN titles?

The process itself is an exemplar of bringing content in from outside 
tiddly wiki, I would hope we could generalise it for obtaining content 
elsewhere and creating a tiddler from it.

For example I have a TiddlyDesktop wiki that can access a local file 
content.
 

But it would be nice if this could be captured in a tiddler with a click. 
However no one seems to be able to do this.

I feel you are doing something similar here.

Great Work

TW Tones.

On Thursday, July 2, 2020 at 11:55:46 AM UTC+10, christia...@gmail.com 
wrote:
>
> Hi all,
>
> I've packaged a modified version of this javascript and interface into a 
> contained plugin. Its available here ->  
> http://ceebeetree.tiddlyspot.com/#Thursday%202nd%20July%202020:%5B%5BThursday%202nd%20July%202020%5D%5D%20%24%3A%2Fplugins%2Fceebee%2Fbookinfo
>   
>
> There were a few improvements that i introduced as part of that packaging, 
> namely:
>
>- using tiddler fields to store the results from openlibrary.org and a 
>wikitext template to present these, instead of building a long text field
>- used the created date field and the <$view> widget and its 
>formatting functions. This removed a lot of date handling in the original 
>javascript
>
>
> Also I provided the ability to add your own 'Notes' on a book  from within 
> the text of the tiddler - while still using this a psuedo-field in the 
> transcluson of the book template. I'm interested if this approach doesn't 
> suffer from low usability  for other people.. so any comments welcome
>
> Enjoy 
> CB   
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/41e35d0a-b709-4600-9ec8-87ddb397d259o%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-07-01 Thread christia...@gmail.com
Hi all,

I've packaged a modified version of this javascript and interface into a 
contained plugin. Its available here ->  
http://ceebeetree.tiddlyspot.com/#Thursday%202nd%20July%202020:%5B%5BThursday%202nd%20July%202020%5D%5D%20%24%3A%2Fplugins%2Fceebee%2Fbookinfo
  

There were a few improvements that i introduced as part of that packaging, 
namely:

   - using tiddler fields to store the results from openlibrary.org and a 
   wikitext template to present these, instead of building a long text field
   - used the created date field and the <$view> widget and its formatting 
   functions. This removed a lot of date handling in the original javascript


Also I provided the ability to add your own 'Notes' on a book  from within 
the text of the tiddler - while still using this a psuedo-field in the 
transcluson of the book template. I'm interested if this approach doesn't 
suffer from low usability  for other people.. so any comments welcome

Enjoy 
CB   

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/538a338d-a593-4082-a45e-cd60b8c9da11n%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-05-21 Thread TonyM
Can someone package this please?

It would be useful in itself but then could be cloned and repurposed.

I do not quie have all the knowledge re javascript modules.

Thank you if possible.

Tony

On Friday, May 22, 2020 at 12:17:20 AM UTC+10, Flan Mou wrote:
>
> Here it is:
>
> ActionGetBookInfoWidget.prototype.invokeAction = 
> function(triggeringWidget,event) {
>   function dateNow() {
> var set = new Date();
> var getDate = set.getDate().toString();
> if (getDate.length == 1){ //example if 1 change to 01
>  getDate = "0"+getDate;
> }
> var getMonth = (set.getMonth()+1).toString();
> if (getMonth.length == 1){
>  getMonth = "0"+getMonth;
> }
> var getYear = set.getFullYear().toString();
> var dateNow = getYear +"-"+ getMonth +"-"+ getDate; //today
> return dateNow;
>   }
>
>   function createBook(title, authors, publisher, isbn, cover) {
> var author_line = "* \'\'Authors:\'\' ".concat(authors);
> var publisher_line = "* \'\'Publisher:\'\' ".concat(publisher);
> var isbn_line = "* \'\'ISBN:\'\' ".concat(isbn);
> var date_line = "* \'\'Date Added:\'\' ".concat(dateNow());
> var cover_line = "[img[".concat(cover,"]]\n");
> var notes_line = "* \'\'Notes:\'\'";
> var text = [author_line, publisher_line, isbn_line, date_line, 
> cover_line, notes_line].join("\n");
> var fields = { tags: "Books", text: text }
> console.log(fields);
>
> $tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(), fields, 
> {title: title}, $tw.wiki.getModificationFields()));
>   }
>
>   // Create URL
>   var base = "https://openlibrary.org/api/books?bibkeys=ISBN:;;
>   var isbn = this.isbn;
>   var url = base.concat(isbn,"=json=data");
>   console.log(url);
>
>   // Do HTTP request
>   window.fetch(url)
> .then(
>   function(response) {
> if (response.status !== 200) {
>   console.log('Looks like there was a problem. Status Code: ' +
> response.status);
>   return;
> }
>
> response.json().then(function(data) {
>   console.log(JSON.stringify(data));
>   var key = "ISBN:".concat(isbn);
>   var title = data[key]["title"];
>   var publisher = data[key]["publishers"][0]["name"];
>   var authors = data[key]["authors"].map(a => a["name"]).join("|");
>   var cover = data[key]["cover"]["medium"];
>   createBook(title, authors, publisher, isbn, cover);
>   alert("Created page for: " + title);
> });
>   }
> )
> .catch(function(err) {
> });
>
>   return true; // Action was invoked
> };
>
> There's also the input tiddler that just invokes this action:
>
> New book ISBN: <$edit-text tiddler="$:/state/isbn" tag="input" default=""
> />
>
>
> <$button>
> <$action-getbookinfo $isbn={{$:/state/isbn}}/>
> Add New Book
> 
>
>
> On Thursday, May 21, 2020 at 1:04:49 AM UTC-7, Mat wrote:
>>
>> Flan, please share your solution if you can.
>>
>> Even if you have a special solution there can be bits of knowledge that 
>> are of use (for example, I'm curious how GETs are used as I hope for this 
>> 
>>  one 
>> day, i.e to fetch cell data from Google Sheets into TW.)
>>
>> Thanks
>>
>> <:-)
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/689294f8-d7c3-4d00-a5d9-408a03ceb00f%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-05-21 Thread Flan Mou
Here it is:

ActionGetBookInfoWidget.prototype.invokeAction = 
function(triggeringWidget,event) {
  function dateNow() {
var set = new Date();
var getDate = set.getDate().toString();
if (getDate.length == 1){ //example if 1 change to 01
 getDate = "0"+getDate;
}
var getMonth = (set.getMonth()+1).toString();
if (getMonth.length == 1){
 getMonth = "0"+getMonth;
}
var getYear = set.getFullYear().toString();
var dateNow = getYear +"-"+ getMonth +"-"+ getDate; //today
return dateNow;
  }

  function createBook(title, authors, publisher, isbn, cover) {
var author_line = "* \'\'Authors:\'\' ".concat(authors);
var publisher_line = "* \'\'Publisher:\'\' ".concat(publisher);
var isbn_line = "* \'\'ISBN:\'\' ".concat(isbn);
var date_line = "* \'\'Date Added:\'\' ".concat(dateNow());
var cover_line = "[img[".concat(cover,"]]\n");
var notes_line = "* \'\'Notes:\'\'";
var text = [author_line, publisher_line, isbn_line, date_line, cover_line, 
notes_line].join("\n");
var fields = { tags: "Books", text: text }
console.log(fields);

$tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(), fields, 
{title: title}, $tw.wiki.getModificationFields()));
  }

  // Create URL
  var base = "https://openlibrary.org/api/books?bibkeys=ISBN:;;
  var isbn = this.isbn;
  var url = base.concat(isbn,"=json=data");
  console.log(url);

  // Do HTTP request
  window.fetch(url)
.then(
  function(response) {
if (response.status !== 200) {
  console.log('Looks like there was a problem. Status Code: ' +
response.status);
  return;
}

response.json().then(function(data) {
  console.log(JSON.stringify(data));
  var key = "ISBN:".concat(isbn);
  var title = data[key]["title"];
  var publisher = data[key]["publishers"][0]["name"];
  var authors = data[key]["authors"].map(a => a["name"]).join("|");
  var cover = data[key]["cover"]["medium"];
  createBook(title, authors, publisher, isbn, cover);
  alert("Created page for: " + title);
});
  }
)
.catch(function(err) {
});

  return true; // Action was invoked
};

There's also the input tiddler that just invokes this action:

New book ISBN: <$edit-text tiddler="$:/state/isbn" tag="input" default=""/>


<$button>
<$action-getbookinfo $isbn={{$:/state/isbn}}/>
Add New Book



On Thursday, May 21, 2020 at 1:04:49 AM UTC-7, Mat wrote:
>
> Flan, please share your solution if you can.
>
> Even if you have a special solution there can be bits of knowledge that 
> are of use (for example, I'm curious how GETs are used as I hope for this 
> 
>  one 
> day, i.e to fetch cell data from Google Sheets into TW.)
>
> Thanks
>
> <:-)
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/b7a33bcf-c4fe-4352-a72d-cd0a5c0f18a0%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-05-21 Thread Mat
Flan, please share your solution if you can.

Even if you have a special solution there can be bits of knowledge that are 
of use (for example, I'm curious how GETs are used as I hope for this 

 one 
day, i.e to fetch cell data from Google Sheets into TW.)

Thanks

<:-)

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywikidev/ba689b32-d708-4dd5-9cba-fb9f26ede34e%40googlegroups.com.


[twdev] Re: New to TW - experienced dev - question

2020-05-20 Thread Flan Mou
This worked out great! I now have exactly what I wanted. Thanks Saq and 
others for your help.

On Wednesday, May 20, 2020 at 7:44:59 AM UTC-7, Saq Imtiaz wrote:
>
> Essentially plugins are about packaging together several tiddlers that add 
> a certain featureset for easier distribution.
>
> To get started you can also skip the packaging as a plugin and just create 
> individual tiddlers.
>
> To just add a widget, create a tiddler with type *application/javascript*, 
> module-type *widget *and put your javascript code for your 
> action-getbookinfo widget in there. Save and reload and that widget will be 
> accessible in all tiddlers.
>
> On Wednesday, May 20, 2020 at 4:42:27 PM UTC+2, Saq Imtiaz wrote:
>>
>> @Flan: think of 
>> plugin
>>
>> as an umbrella term for tiddlers that add functionality to TiddlyWiki. A 
>> plugin consists of one or more tiddlers. A javascript tiddler with 
>> module-type 
>> widget
>>
>> can define a widget. A plugin can contain one or several such widgets.
>>
>> In this case, one of your plugin tiddlers would be a tiddler that has the 
>> javascript code for your widget. For example:
>>
>> If the plugin is $:/plugins/flan/bookinfo, it may contain several 
>> tiddlers including for example $:/plugins/flan/bookinfo/widgets/getbookinfo 
>> which has the code for your widget.
>>
>> A tiddler defining a widget needs the field *type* with value 
>> *application/javascript*, and the field *module-type* with value *widget*
>>
>>
>>
>> On Wednesday, May 20, 2020 at 4:34:41 PM UTC+2, Flan Mou wrote:
>>>
>>> Hi Saq,
>>>
>>> This is very useful, thanks. I'm now a bit confused: it sounds like I 
>>> want to create a widget and not a plugin? What's the difference?
>>>
>>> Is there any documentation available along the lines "How to create your 
>>> first widget"?
>>>
>>> If not:
>>> - I'm looking at action-createtiddler.js as a reference example. 
>>> - If I create an action-getbookinfo as you suggest, where/how do I 
>>> install this so that Tiddlers can access the widget?
>>> - Do I put it core/modules/widgets?
>>> - Will it be available for use automatically or do I have to do 
>>> something else? 
>>>
>>> Thanks for all your help. I'm trying to use the online documentation but 
>>> it's not very friendly to someone new to TW.
>>>
>>> On Wednesday, May 20, 2020 at 1:28:33 AM UTC-7, Saq Imtiaz wrote:

 Plugin javascript tiddlers need the correct module-type to determine 
 how they are made available/run.
 https://tiddlywiki.com/#ModuleType

 Here is what I recommend to get you started:

 To get the user input of what ISBN to look up, use an edit-text widget 
 with a temporary tiddler like $:/myplugin/isbn-search
 https://tiddlywiki.com/#EditTextWidget

 Since you want to execute an action on userinput, that is look up the 
 isbn, use a button widget to trigger a custom action widget.

 You can model your action widget on

 https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/widgets/action-setfield.js

 For starters, accept a single parameter, the isbn, make the http 
 request and in the callback, parse the response and create a tiddler.

 For an action widget called action-getbookinfo, it would be invoked 
 like this inside the button widget:
 <$action-getbookinfo $isbn={{$:/myplugin/isbn-search}} />

 On Tuesday, May 19, 2020 at 4:57:32 PM UTC+2, Flan Mou wrote:
>
> Update: I followed the instructions here:
>
>
> https://tiddlywiki.com/dev/static/How%2520to%2520create%2520plugins%2520in%2520the%2520browser.html
>
> And created a plugin which simply contains:
>
> (function () { alert("Test alert"); })
>
> Everything got packed and saved, and the plugin appears installed. But 
> when I reload the alert box doesn't appear. I would have expected the 
> code 
> inside an installed plugin to run upon startup. How can I get TW to 
> execute 
> my plugin code?
>
> On Tuesday, May 19, 2020 at 7:20:38 AM UTC-7, Flan Mou wrote:
>
>> Yes, for example there is the OpenLibrary API:
>>
>> https://openlibrary.org/developers/api
>>
>> I'm fine with interacting with the API, it's just that I'm not sure 
>> how to build even a very simple request within TW. I was expecting to be 
>> able to create an HTML tiddler, add a  tag, and write some 
>> Javascript with XMLHttpRequest() within it. But it seems that's not 
>> possible. For example I created an HTML Tiddler with:
>>
>>