Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step #20.36 Sorted images are not persisted #299

Open
acaneva opened this issue Nov 21, 2016 · 0 comments
Open

Step #20.36 Sorted images are not persisted #299

acaneva opened this issue Nov 21, 2016 · 0 comments

Comments

@acaneva
Copy link

acaneva commented Nov 21, 2016

[Socially - Angular 1]
Hi,
Don´t know if this is an issue, but following the tutorial couldn´t get images order to be persisted after sorting in the view. My take on this was sorting files array (instead of thumbs) and creating a new component to show corresponding thumb image. Probably not a good practice, but here it goes:

Step 20.36 imports/ui/components/partyUpload/partyUpload.html

    <div layout="row" class="images-container-title" sv-root sv-part="partyUpload.files">
        <div  sv-element 
              class="party-image-container" 
              ng-class="{'main-image': $index === 0}" 
              ng-repeat="image in partyUpload.files" >
              <thumb-image image="image"></thumb-image>
        </div>
    </div>

Then, new view imports/ui/components/thumbImage/thumbImage.html

<img draggable="false"  ng-src="{{ thumbImage.thumb.url }}" />

and new component imports/ui/components/thumbImage/thumbImage.js

import angular from 'angular';
import angularMeteor from 'angular-meteor';
 
import template from './thumbImage.html';
import { Thumbs } from '../../../api/images';
 
class ThumbImage {
  constructor($scope, $reactive) {
    'ngInject';
    $reactive(this).attach($scope);
    this.subscribe('thumbs');

    this.helpers({
      thumb() {
        const image = this.getReactively('image', true);
        if (image) {
          return Thumbs.findOne({
            originalStore: 'images',
            originalId: image 
          });
        }
      }
    });
  }
}
 
const name = 'thumbImage';
 
// create a module
export default angular.module(name, [
  angularMeteor
]).component(name, {
  template,
  bindings: {
    image: '<'
  },
  controllerAs: name,
  controller: ThumbImage
});

Imported into Step 20.37 imports/ui/components/partyUpload/partyUpload.js

import { name as ThumbImage } from '../thumbImage/thumbImage';
...
export default angular.module(name, [
  angularMeteor,
  ngFileUpload,
  'ngImgCrop',
  'angular-sortable-view',
  ThumbImage
]).component(name, {

Finally, changed Thumbs publication Step 20.31 in imports/api/images/publish.js to:

  Meteor.publish('thumbs', function() {
    return Thumbs.find({});
  });

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant