michaelkrone / generator-material-app

Yet another yeoman generator for scaffolding a simple Node.js/Express/MongoDB/Angular.js app using some material design elements.
MIT License
177 stars 47 forks source link

i can not add a new record in new generated entity #25

Closed hugotown closed 8 years ago

hugotown commented 9 years ago

Hi i got this issue

I click on create one. The app shows create modal, but immediately closes the modal without giving me a chance to add the record

No errors in developer console

closewindow

immediately closes the modal

screen shot 2015-10-22 at 15 16 59
michaelkrone commented 9 years ago

Hi @ruizhit. Thank you, I will have a look at this at well.

ricsard commented 9 years ago

@ruizhit I also have this problem, as I see we faced with the same issues, I didn't find the solution for this yet, but I would appreciate if we find a solution for sg we will share it here :) @michaelkrone :+1:

Bernix01 commented 9 years ago

Hi, in my case for some reason the paths are generated with "\" instead of "/" which got scaped causing the dialog to hide... the workaround was going through

entity.js main/main.js list/list.js list/detail/detail.js list/edit/edit.js

and change the "\" with "/" after that the dialog didn't dissappear.

michaelkrone commented 8 years ago

Hi @Bernix01. Which paths were generated with a "\"? The routes?

Bernix01 commented 8 years ago

@michaelkrone those for the html templates.

tenchugecko commented 8 years ago

i got it working, but then suddenly it stopped working for a different reason

create hides immediately update works and persists in mongodb, but gives an error

the server sends a big response, but it still says:

im on latest node n stuff and i use vs2015 could cr lf / lf in the sources be the issue?

Creeate Users works, but update also gives server error

PUT /api/schedules/564fbc822d05c99c62f9717a 500 21ms
defaultErrorHandler /api/schedules/564fbc822d05c99c62f9717a 200 { [TypeError: Cannot read property 'paramName' of null]
  domain:
   Domain {
     domain: null,
     _events: { error: [Function: handleError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [ [Object], [Object] ],
     '__$cntxt__': { request: [Object] } },
  domainThrown: true }
TypeError: Cannot read property 'paramName' of null
    at G:\_soundsets\_projects\SoundSetsWebadmin\sswa\server\lib\controllers\param.controller.js:114:12
    at model.<anonymous> (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongoose\lib\document.js:1730:20)
    at next_ (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\hooks-fixed\hooks.js:89:34)
    at fnWrapper (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\hooks-fixed\hooks.js:186:18)
    at G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongoose\lib\model.js:295:13
    at G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongoose\lib\model.js:230:5
    at G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongoose\lib\model.js:170:9
    at handleCallback (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongoose\node_modules\mongodb\lib\uti
ls.js:96:12)
    at G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongoose\node_modules\mongodb\lib\collection.js:974:5

    at G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongodb-core\lib\topologies\server.js:772:13
    at bound (domain.js:280:14)
    at runBound (domain.js:293:12)
    at Callbacks.emit (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongodb-core\lib\topologies\server.js
:95:3)
    at null.messageHandler (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongodb-core\lib\topologies\serv
er.js:243:23)
    at Socket.<anonymous> (G:\_soundsets\_projects\SoundSetsWebadmin\sswa\node_modules\mongodb-core\lib\connection\conne
ction.js:262:22)
    at emitOne (events.js:77:13)
'''
tenchugecko commented 8 years ago

Ok got the update thingy:

at \server\lib\controllers\param.controller.js:114:12 Search for "this" inside the mongodbCrud closures and do the var self = this to get this into the scope of the closure

update: function (req, res) {

        var self = this;

        if (req.body._id) {
            delete req.body._id;
        }

        var self = this;
        var bodyData = _.omit(req.body, this.omit);
        var updated = _.merge(req[this.paramName], bodyData);

        updated.save(function (err) {
            if (err) {
                return res.handleError(err);
            }

            req[self.paramName] = updated;
            return res.ok(self.getResponseObject(updated));
        });
    },
tenchugecko commented 8 years ago

the other thing about that create window auto hiding

removing the hide from statechanged "fixes" it, so - what is it i'm not understanding here :)

function onEnterScheduleListCreateView($rootScope, $state, $mdDialog) {
        var unregisterListener = $rootScope.$on('$stateChangeStart', onStateChange);

        $mdDialog.show({
            controller: 'ScheduleCreateController',
            controllerAs: 'create',
            templateUrl: 'app/schedules/create/create.html',
            clickOutsideToClose: false
        }).then(transitionTo, transitionTo);

        /**
         * Function executed when resolving or rejecting the
         * dialog promise.
         *
         * @param {*} answer - The result of the dialog callback
         * @returns {promise}
         */
        function transitionTo(answer) {
            return $state.transitionTo('schedule.list');
        }

        /**
         * Function executed when changing the state.
         * Closes the create dialog
         */
        function onStateChange() {
            unregisterListener();
        //  $mdDialog.hide();
        }
    }
Bernix01 commented 8 years ago

As @tenchugecko suggested

         /**
         * Function executed when changing the state.
         * Closes the create dialog
         */
        function onStateChange() {
            unregisterListener();
        //  $mdDialog.hide();
        }

fixes the auto hiding problem, now all seems to work.

tenchugecko commented 8 years ago

so : why is the onStateChanged fired right away on these views?

-> and not why is it not fired on the Admin/Users view.

find out on the next episode of jsi

michaelkrone commented 8 years ago

Should be closed with #38