vendredi 11 septembre 2015

auto close modal dialog google sheets - google apps script

I have a google sheet that I am connecting to a sql server to allow some non-sql server folks a tool to view and make small edits to data in a table. I have the read and write set up for the server, but want to create a "loading..." modal while data is being refreshed to prevent any issues. I can get the modal to pop up but am trying to figure out how to auto-close the dialog as soon as the code is finished firing.

An example I have set up is:

function testpop () {
  var htmlOutput = HtmlService
    .createHtmlOutput('<p> This box will close when the data has finished loading.</p>')
    .setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .setWidth(250)
    .setHeight(200);
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Loading...');
  sleep(1000);
//close the dialog
}

I know this can be called on a client side but need it to be handled in the gs so it fires when the code is done. Thanks.



via Chebli Mohamed

Highlight multiple items of ListView

This problem is not new. However, any of the solution is not working for me.

I have got a ListView with several TextView which is populated from data fetched from SQLite. User can LongPress on one item to select multiple items of ListView and further choose to delete them from database.

What I want to do next is to highlight those items which are selected by user after the first LongPress (including the first one).
Here is the snippet of my ListView.

    <ListView
        ...
        android:drawSelectorOnTop="false"
        android:listSelector="@android:color/darker_gray"
        android:choiceMode="multipleChoice"/>

This is highlighting the item of ListView but not the first one on which the user will do the LongPress. And only highlight one of the item on ListView, whenever user chooses another item the current one is resetted and the background of the new item is changed, and this continues.



via Chebli Mohamed

Implementation wice_grid for one-to-many association

Image has a one-to-many association with Category:

# Category model:
has_many :images
# Image model:
has_one :category
Images migration file:
t.references :category, index: true, foreign_key: true

I'm trying to implement a grid view using the wice_grid gem. This works but one line is failing. The following works in the index view:

g.column name: 'Category', attribute: 'category_id', auto_reload: true, html: {id: 'grid-cells'} do |image|
  image.category_id
end

But this displays the number/id of the category, while I want it to display its name. If I try image.category instead of image.category_id there's an error:

PG::UndefinedColumn: ERROR:  column categories.image_id does not exist
LINE 1: SELECT  "categories".* FROM "categories" WHERE "categories"."image_id...

How can I have it display the category name instead of the id of the category?

Controller method:

def index
  @images_grid = initialize_grid(Image,
  # include: :category  # Do I need this? Tried it with and without
  per_page: 40)
end



via Chebli Mohamed

How to properly format logs

Is there a proper way to logging?

I want my web application to log every received call, just as any regular web server would do.

Are there some brilliant approaches to logging out there? My goal, aside from tracking errors, is to be able at some point in the future to get valuable statistical information on the server activity.

JSON and XML are verbose, while space-delimited logs (as in nginx & apache) are tedious to parse.

Did I miss something great?



via Chebli Mohamed

In Vanilla JavaScript, how do I structure my app when having multiple Models/Views/Controllers?

I'm trying to get a practical grasp of MVC model implementation (not the conceptual understanding) in JavaScript.

As for the start, I thought it would be worth making an effort and try building a MVC app in plain JS. I've read dozens of articles and book chapters referring to MVC and its variations. Of course I googled lots of examples to see how it's done for real. The most understandable and with the proper meaning is in my opinion this one:

http://ift.tt/1FBZo6q

In the end, I was able to refactor my own app in the todomvc-vanillajs way.

However, there is one thing that still bothers me. All these apps and examples are very basic, so there is only one Model, View and Controller specified for the whole app.

What if I wanted to add more (equally complex) features to such app?

Should I add them one by one to my controller.js view.js and model.js files or whether should I stop developing spaghetti code and add new files instead, thus creating new models, controllers and views for each of the new feature individually?

It seems to me, that every feature should have its own view, controller and model, or at least, could have, depending on the subjective evaluation. But I'm not quite sure how such implementation should look at this situation in terms of code structure, namespacing etc.?

What if I want to imitate a scale by creating multiple views, models and controllers on every single functionality like e.g. handling an "add task to the list" or "delete the task" actions.

For the purpose of my dilemma, I've created my own MVC draft, which has two models, controllers and views. Whether such an approach would make sense? What happens when further developing my application, I quickly get to the point where I have dozens and more specific (coresponding) models, views and controllers.

Heres is the aforementioned fiddle.

;(function () {
    'use strict';
    /**
     * @file ./App.js
     */ 

    var App = {
        Model : {},
        Controller : {},
        View : {}
    };

    console.log('start');

    window.App = App;

})();
/* -------------Views-folder----------------------*/
    /* -------------separate-file-----------------------*/
(function () {
    'use strict';
    /**
     * @file Views/buildAdd.js
     */ 

    var buildAdd = {
        // render

        // event

            // pass the reference to event handler in Controller
    };

    App.View.buildAdd = buildAdd;

})(App);
    /* -------------separate-file-----------------------*/
(function () {
    'use strict';
    /**
     * @file Views/buildDelete.js
     */ 

    var buildDelete = {
        // render

        // event

            // pass the reference to event handler in Controller
    };

    App.View.buildDelete = buildDelete; 

})(App);
/* -------------Controllers-folder----------------------*/
    /* -------------separate-file-----------------------*/
(function () {
    'use strict';

    var addController = {
        // handle the event and decide what the Model has to do

        // handle the response from Model and tells the View how to update 
    };

    App.Controller.addController = addController;

})(App);
/* -------------separate-file-----------------------*/
(function () {
    'use strict';

    var deleteController = {
        // handle the event and decide what the Model has to do

        // handle the response from Model and tells the View how to update
    };

    App.Controller.deleteController = deleteController;

})(App);
    /* -------------Models-folder----------------------*/
    /* -------------separate-file-----------------------*/
(function () {
    'use strict';

    var addModel = {
        // send request

        // get response
    };

    App.Model.addModel = addModel;

})(App);
    /* -------------separate-file-----------------------*/
(function () {
    'use strict';

    var deleteModel = {
        // send request

        // get response
    };

    App.Model.deleteModel = deleteModel;

})(App);
    /* -------------separate-file-----------------------*/

Thus, I found this question very similar to mine, but the provided answers are not entirely satisfactory, at least to me.



via Chebli Mohamed

JS: css property and value in one variable

var trns1 = '"transition": "all 1s"';

Why doesnt that work?

$('#box').css({"transform": "translate(xy)", trns1 });

Shouldnt that be exactly the same like:

$('#box').css({"transform": "translate(xy)", "transition": "all 1s" });

?



via Chebli Mohamed

Not sure why this code was added?

The home page for this handmade furniture website had this code

$outputstrg = htmlentities("<url>"). "<br />". htmlentities("<loc>").$urltest .$town . htmlentities("</loc>") . "<br />" . htmlentities("</url>");

I removed it and it had no effect, any idea why it was there and what it was supposed to do?



via Chebli Mohamed