[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

Swiki tool implemented using Mobile framework

"Ensure Mobile framework is loaded and verify we are running in a supported platform"
(SwikiCodeRobot @ #mobile) process: #s8-media tagged: #core.


"Creating SwikiTool  Model"
Object
	subclass: #SwikiTool
	instanceVariableNames: ' categoryNames tags swikiName pages'
	category: #Swiki !

SwikiTool buildAccessors: #(
        tags
        #( swikiName initialize '''s8-media''' )
        #( categoryNames initialize '''test''' )
	#( pages initialize #Array )

)!

! SwikiTool  methodsFor: #specs !
platformPath
	" Private - Return the path for folder of platform files. "

	^''! !

! SwikiTool  methodsFor: #specs !
resourcesPath
	" Private - Return the path for folder of resources. 
	if apply include /images/ here"

	^'http://swiki.smalltalking.net/s8-media/uploads/150/'! !


 !  SwikiTool  methodsFor: #robot !
searchPages
	" Search pages according to filters. "
	
	|categoriesArray tagsArray|
	
        self pages: Array new. 
	categoriesArray := (self categoryNames asArrayOfSubstringsSeparatedBy: $,) collect: [:each | each trimBlanks].
	tagsArray := (self tags asArrayOfSubstringsSeparatedBy: $,) collect: [:each | each trimBlanks].
	self print:'CATEGORIES ARRAY: ', categoriesArray.
	self print:'TAGS ARRAY: ', tagsArray.
        categoriesArray do: [ :eachCategory|
               (SwikiCodeRobot @ eachCategory)
    		withPagesIn: self swikiName tagged: tagsArray
    		do: [:thePages| 
    			self pages addAll: thePages
			 ].        
          ].
          self print: self pages.

		! !


"Compiling spec and open the UI"
| spec tab swikiPagesView |

swikiPagesView := (
 (#class -> #MobileEditor ),
 (#configuration -> (
   (#listeners -> ( (#needsTitle -> [:coordinator | 'Swiki Pages']) )),
  (#navigationBar -> (
        (#right ->
          (#right -> [:coordinator | coordinator--'comments-save'. coordinator model ] )
        )
    )),
 (#widgets -> (
           (#pages -> (
				(#type -> #list ),
				(#configuration ->(
					(#order -> 1),
					(#listeners -> (
						(#needsTitle -> ['Swiki Pages in s8-media'] ),
						(#needsItems -> [:coordinator | self print: 'NEEDS ITEMS'.coordinator applicationModel pages ] ),
						(#configureCell:for:in:coordinator: -> [:cell :item :aList :coordinator |
							coordinator configure: cell title: '#',item first description: item second
						]),
						(#selected: -> [:item :coordinator |
							coordinator application openPage: item in: coordinator
						])
					))
				))
			)) 
                ))
 ))
).
tab :=  (
     	(#tool -> 'swiki' ),
     	(#coordinator -> 
     		(
    			(#class -> #MobileEditor ),
      			(#configuration -> 
      				(
         				(#title -> 'Test Widgets'),
         				(#navigationBar -> (
          					(#right ->
            					(#right -> [:coordinator | 
            						(coordinator @ #swikiField) done.
            						(coordinator @ #categoryField) done.
            						(coordinator @ #tagsField) done.
            						
            						coordinator applicationModel 
            							swikiName: (coordinator @ #swikiField ) text trimBlanks;
            							categoryNames: (coordinator @ #categoryField ) text trimBlanks;
            							tags: (coordinator @ #tagsField ) text trimBlanks;
                                                                searchPages;
            							yourself.
            						coordinator thread next: (coordinator newTemplateAt: #SwikiPages) ])
          					))
         				),
         				(#widgets -> (
           					
             				(#swikiLabel -> (
            					(#type -> #label ),
            					(#configuration -> (
               						(#order -> 1 ), 
               						(#height -> 40), 
               						"(#backgroundColor -> 'white'),"
               						(#text -> 'Swiki')",
               						(#color -> 'blue')"
                				)) 
                			)),
                                          (#swikiField -> (
            					(#type -> #textField ),
            					(#configuration -> (
               						(#order -> 2 ),
               						(#height -> 40),
               						(#defaultText -> 's8-media'),
               						(#width -> 300), 
                					(#background -> 'white'),
                					(#color -> 'black'),
                					(#keyboardType -> 'numberPad'),
                					(#border -> 'roundedRect'),
                					(#autocapitalizationType -> #none),
                					(#autocorrectionType -> #none),
                					(#spellCheckingType -> #none),
                					(#returnKeyType -> #done),
               						(#listeners -> (
                						(#done: -> [:coordinator :field | coordinator applicationModel swikiName: (coordinator @ #swikiField) text.  ])
                
     								)) 
     							))  
     						)),

                                          (#separator -> (
            					(#type -> #line ),
            					(#configuration -> (
               						(#order -> 3 ),
               						(#height -> 10), 
                					(#background -> 'blue') 
                				  )) 
                			     )),
				           (#categoryLabel -> (
            					(#type -> #label ),
            					(#configuration -> (
               						(#order -> 4 ), 
               						(#height -> 40), 
               						"(#backgroundColor -> 'white'),"
               						(#text -> 'Category')",
               						(#color -> 'blue')"
                				)) 
                			)),
                                          (#categoryField -> (
            					(#type -> #textField ),
            					(#configuration -> (
               						(#order -> 5 ),
               						(#height -> 40),
               						(#defaultText -> 'Test'),
               						(#width -> 300), 
                					(#background -> 'white'),
                					(#color -> 'black'),
                					(#keyboardType -> 'numberPad'),
                					(#border -> 'roundedRect'),
                					(#autocapitalizationType -> #none),
                					(#autocorrectionType -> #none),
                					(#spellCheckingType -> #none),
                					(#returnKeyType -> #done),
               						(#listeners -> (
                						(#done: -> [:coordinator :field | coordinator applicationModel swikiName: (coordinator @ #categoryField) text.  ])
                
     								)) 
     							))  
     						)),

                                          (#separator2 -> (
            					(#type -> #line ),
            					(#configuration -> (
               						(#order -> 6 ),
               						(#height -> 10), 
                					(#background -> 'blue') 
                				 )) 
                			     )),
                                            (#tagsLabel -> (
            					(#type -> #label ),
            					(#configuration -> (
               						(#order -> 7 ), 
               						(#height -> 40), 
               						"(#backgroundColor -> 'white'),"
               						(#text -> 'Tags')",
               						(#color -> 'blue')"
                				)) 
                			)),
                                          (#tagsField -> (
            					(#type -> #textField ),
            					(#configuration -> (
               						(#order -> 8 ),
               						(#height -> 40),
               						(#defaultText -> 's8-media'),
               						(#width -> 500), 
                					(#background -> 'white'),
                					(#color -> 'black'),
                					(#keyboardType -> 'numberPad'),
                					(#border -> 'roundedRect'),
                					(#autocapitalizationType -> #none),
                					(#autocorrectionType -> #none),
                					(#spellCheckingType -> #none),
                					(#returnKeyType -> #done),
               						(#listeners -> (
                						(#done: -> [:coordinator :field | coordinator applicationModel swikiName: (coordinator @ #swikiField) text.  ])
                
     								)) 
     							))  
     						)),

                                          (#separator3 -> (
            					(#type -> #line ),
            					(#configuration -> (
               						(#order ->9 ),
               						(#height -> 70), 
                					(#background -> 'blue') 
                				)) 
                			   ))	
                                    
                	
                
                	
                
                	)),
         				
			(#listeners -> (
				(#built: -> [:coordinator | self print: coordinator applicationModel toString. (coordinator @ #swikiField) text: (coordinator applicationModel swikiName). 
                                   (coordinator @ #categoryField) text: (coordinator applicationModel categoryNames)])
    		)) 
    	)
      ) 
    )
	) 
    ).
spec := (
 (#threads -> ((1 -> tab)) ),
(#templates -> (
   (#SwikiPages -> swikiPagesView)
 )),
 (#listeners -> (#needsModel -> [ SwikiTool new  yourself. ]))
) json.
MobileApplication open: spec.